Skip to content
Related Articles

Related Articles

bits.Reverse64() Function in Golang with Examples
  • Last Updated : 19 Apr, 2020
GeeksforGeeks - Summer Carnival Banner

Go language provides inbuilt support for bits to implement bit counting and manipulation functions for the predeclared unsigned integer types with the help of bits package. This package provides Reverse64() function which is used to find the reversed order of the value of a. To access Reverse64() function you need to add a math/bits package in your program with the help of the import keyword.

Syntax:

func Reverse64(a uint64) uint64

Parameters: This function takes one parameter of uint64 type, i.e., a.

Return Value: This function returns the value of a with its bits in reversed order.

Example 1:






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

Output:

Reverse order of 5: 1010000000000000000000000000000000000000000000000000000000000000

Example 2 :




// Golang program to illustrate bits.Reverse64() Function
package main
  
import (
    "fmt"
    "math/bits"
)
  
// Main function
func main() {
  
    // Using Reverse64() function
    a1 := bits.Reverse64(9)
    fmt.Printf("Reverse64(%064b) := %b\n", 9, a1)
  
    a2 := bits.Reverse64(13)
    fmt.Printf("Reverse64(%064b) := %b\n", 13, a2)
  
}

Output:

Reverse64(0000000000000000000000000000000000000000000000000000000000001001) := 1001000000000000000000000000000000000000000000000000000000000000
Reverse64(0000000000000000000000000000000000000000000000000000000000001101) := 1011000000000000000000000000000000000000000000000000000000000000

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
Recommended Articles
Page :