📜  Golang 中的 bits.LeadingZeros16()函数示例

📅  最后修改于: 2021-10-25 02:38:55             🧑  作者: Mango

bits.LeadingZeros16() Golang 中的函数用于查找给定数字中前导零位的数量。如果给定的数字等于 0,则此方法将返回 16。要访问此函数,需要在程序中导入 math/bits 包。

示例 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)
   
}