當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Golang bits.LeadingZeros16()用法及代碼示例

Golang中的bits.LeadingZeros16()函數用於查找給定數字中前導零位的數量。如果給定的數字等於零,則此方法將返回16。要訪問此函數,需要在程序中導入math /bits包。

用法:
func LeadingZeros16(x uint16) int

參數:此函數采用uint16類型的一個參數,即x。

返回值:此函數返回x中前導零位的總數。

範例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) 
   
}

輸出:

Total number of leading zero bits: 14

範例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) 
   
}

輸出:

Total number of leading zero bits: 16

相關用法


注:本文由純淨天空篩選整理自PranchalKatiyar大神的英文原創作品 bits.LeadingZeros16() Function in Golang With Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。