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