bits.TrailingZeros8() Function in Golang with Examples
Last Updated :
19 Apr, 2020
Go language provides inbuilt support for bits to implement bit counting and manipulation functions for the predeclared unsigned integer types with the help of bits package. This package provides TrailingZeros8() function which is used to find the number of trailing zero bits in a and the result is 8 for a == 0. To access TrailingZeros8() function you need to add a math/bits package in your program with the help of the import keyword.
Syntax:
func TrailingZeros8(a uint8) int
Parameters: This function takes one parameter of uint8 type, i.e., a.
Return Value: This function returns total number of trailing zero bits in a.
Example 1 :
package main
import (
"fmt"
"math/bits"
)
func main() {
a := bits.TrailingZeros8(6)
fmt.Printf( "Total number of trailing " +
"zero bits in %d: %d" , 6, a)
}
|
Output:
Total number of trailing zero bits in 6: 1
Example 2 :
package main
import (
"fmt"
"math/bits"
)
func main() {
a1 := bits.TrailingZeros8(8)
fmt.Printf( "TrailingZeros8(%08b)) := %d\n" , 8, a1)
a2 := bits.TrailingZeros8(13)
fmt.Printf( "TrailingZeros8(%08b) := %d\n" , 13, a2)
}
|
Output:
TrailingZeros8(00001000)) := 3
TrailingZeros8(00001101) := 0
Share your thoughts in the comments
Please Login to comment...