bits.LeadingZeros32() Function in Golang With Examples
bits.LeadingZeros32() Function in Golang is used to find the number of the leading zero bits in the given number. If the given number is equal to zero, then this function will return 32. To access this function, one needs to imports the math/bits package in the program.
Syntax:
func LeadingZeros32(x uint32) intParameters: This function takes one parameter of uint32 type, i.e., x.
Return Value: This function returns a total number of leading zero bits in x.
Example 1:
// Golang program to illustrate // bits.LeadingZeros32() Function package main import ( "fmt" "math/bits" ) // Main function func main() { // Using LeadingZeros32() function x := bits.LeadingZeros32(9) fmt.Println( "Total number of leading zero bits: " , x) } |
Output:
Total number of leading zero bits: 28
Example 2:
// Golang program to illustrate // bits.LeadingZeros32() Function package main import ( "fmt" "math/bits" ) // Main function func main() { // Using LeadingZeros32() function x := bits.LeadingZeros32(0) fmt.Println( "Total number of leading zero bits: " , x) } |
Output:
Total number of leading zero bits: 32
Contact Us