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