📌  相关文章
📜  带有示例的 Golang 中的 bits.ReverseBytes64()函数

📅  最后修改于: 2021-10-24 13:32:18             🧑  作者: Mango

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

句法:

func ReverseBytes64(a uint64) uint64

参数:该函数接受一个 uint64 类型的参数,即 a。

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

示例 1:

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

输出:

Reverse order of 7: 11100000000000000000000000000000000000000000000000000000000

示例 2:

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

输出: