当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Golang bits.LeadingZeros8()用法及代码示例


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

用法:
func LeadingZeros8(x uint8) int

参数:此函数采用uint8类型的一个参数,即x。

返回值:此函数返回x中前导零位的总数。

范例1:



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

输出:

Total number of leading zero bits: 5

范例2:

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

输出:

Total number of leading zero bits: 8

相关用法


注:本文由纯净天空筛选整理自PranchalKatiyar大神的英文原创作品 bits.LeadingZeros8() Function in Golang with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。