bits.LeadingZeros64() Golang 中的函数用于查找给定数字中前导零位的数量。如果给定的数字等于 0,则此函数将返回 64。要访问此函数,需要在程序中导入 math/bits 包。
Syntax:
Parameters: This function takes one parameter of uint64 type, i.e., x.
Return Value: This function returns a total number of leading zero bits in x.
示例 1:
func LeadingZeros64(x uint64) int
输出:
// Golang program to illustrate
// bits.LeadingZeros64() Function
package main
import (
"fmt"
"math/bits"
)
// Main function
func main() {
// Using LeadingZeros64() function
x := bits.LeadingZeros64(55)
fmt.Println("Total number of leading zero bits: ", x)
}
示例 2:
Total number of leading zero bits: 58
输出:
// Golang program to illustrate
// bits.LeadingZeros64() Function
package main
import (
"fmt"
"math/bits"
)
// Main function
func main() {
// Using LeadingZeros64() function
x := bits.LeadingZeros64(0)
fmt.Println("Total number of leading zero bits: ", x)
}