Related Articles
bits.LeadingZeros16() Function in Golang With Examples
• Last Updated : 19 Apr, 2020

bits.LeadingZeros16() 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 method will return 16. To access this function, one needs to imports the math/bits package in the program.

Syntax:

```func LeadingZeros16(x uint16) int
```

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.

Example 1:

 `// 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)``  ` `}`

Output:

```Total number of leading zero bits:  14
```

Example 2:

 `// 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)``  ` `}`

Output:

```Total number of leading zero bits:  16
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up