Go語言提供了對位的內置支持,以借助bits包對預聲明的無符號整數類型實現位計數和操作函數。該軟件包提供了TrailingZeros64()函數,該函數用於查找a中的尾隨零位的數目,而a == 0的結果為64。要訪問TrailingZeros64()函數,您需要在程序中添加math /bits軟件包借助import關鍵字。
用法:
func TrailingZeros64(a uint64) int
參數:此函數采用uint64類型的一個參數,即a。
返回值:此函數返回a中尾隨零位的總數。
範例1:
// Golang program to illustrate bits.TrailingZeros64() Function
package main
import (
"fmt"
"math/bits"
)
// Main function
func main() {
// Using TrailingZeros64() function
a:= bits.TrailingZeros64(15)
fmt.Printf("Total number of trailing"+
" zero bits in %d:%d", 15, a)
}
輸出:
Total number of trailing zero bits in 15:0
範例2:
// Golang program to illustrate bits.TrailingZeros64() Function
package main
import (
"fmt"
"math/bits"
)
// Main function
func main() {
// Using TrailingZeros64() function
a1:= bits.TrailingZeros64(8)
fmt.Printf("TrailingZeros64(%064b)):= %d\n", 8, a1)
a2:= bits.TrailingZeros64(24)
fmt.Printf("TrailingZeros64(%064b):= %d\n", 24, a2)
}
輸出:
TrailingZeros64(0000000000000000000000000000000000000000000000000000000000001000)):= 3 TrailingZeros64(0000000000000000000000000000000000000000000000000000000000011000):= 3
相關用法
- Golang math.Lgamma()用法及代碼示例
- Golang math.Float64bits()用法及代碼示例
- Golang atomic.AddInt64()用法及代碼示例
- Golang atomic.StoreInt64()用法及代碼示例
- Golang reflect.FieldByIndex()用法及代碼示例
- Golang string.Contains用法及代碼示例
- Golang bits.Sub()用法及代碼示例
- Golang io.PipeWriter.CloseWithError()用法及代碼示例
- Golang time.Round()用法及代碼示例
- Golang reflect.AppendSlice()用法及代碼示例
- Golang reflect.ChanOf()用法及代碼示例
- Golang flag.Bool()用法及代碼示例
- Golang time.Sleep()用法及代碼示例
- Golang time.Time.Year()用法及代碼示例
- Golang reflect.DeepEqual()用法及代碼示例
- Golang reflect.Indirect()用法及代碼示例
- Golang reflect.CanAddr()用法及代碼示例
- Golang reflect.CanInterface()用法及代碼示例
- Golang reflect.CanSet()用法及代碼示例
- Golang reflect.Cap()用法及代碼示例
注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 bits.TrailingZeros64() Function in Golang with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。