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


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


Go语言提供了对位的内置支持,以借助bits包对预声明的无符号整数类型实现位计数和操作函数。该包提供ReverseBytes32()函数,该函数用于查找a值的倒序。要访问ReverseBytes32()函数,您需要借助import关键字在程序中添加math /bits包。

用法:

func ReverseBytes32(a uint32) uint32

参数:此函数采用uint32类型的一个参数,即a。

返回值:此函数以相反的顺序返回其位的a值。

范例1:



// Golang program to illustrate  
// bits.ReverseBytes32() Function 
  
package main 
  
import ( 
    "fmt"
    "math/bits"
) 
  
// Main function 
func main() { 
  
    // Finding the reverse order of a 
    // Using ReverseBytes32() function 
    a:= bits.ReverseBytes32(7) 
    fmt.Printf("Reverse order of %d:%b", 7, a) 
  
}

输出:

Reverse order of 7:111000000000000000000000000

范例2:

// Golang program to illustrate 
// bits.ReverseBytes32() Function 
package main 
  
import ( 
    "fmt"
    "math/bits"
) 
  
// Main function 
func main() { 
  
    // Finding the reverse order of a 
    // Using ReverseBytes32() function 
    a1:= bits.ReverseBytes32(3) 
    fmt.Printf("ReverseBytes32(%032b):= %b\n", 3, a1) 
  
    a2:= bits.ReverseBytes32(9) 
    fmt.Printf("ReverseBytes32(%032b):= %b\n", 9, a2) 
  
}

输出:

ReverseBytes32(00000000000000000000000000000011):= 11000000000000000000000000
ReverseBytes32(00000000000000000000000000001001):= 1001000000000000000000000000



相关用法


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