bits.Reverse32() Function in Golang with Examples

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 Reverse32() function which is used to find the reversed order of the value of a. To access the Reverse32() function you need to add a math/bits package in your program with the help of the import keyword.

Syntax:

func Reverse32(a uint32) uint32

Parameters: This function takes one parameter of uint32 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.Reverse32() Function
package main
  
import (
    "fmt"
    "math/bits"
)
  
// Main function
func main() {
  
    // Using Reverse32() function
    a := bits.Reverse32(5)
    fmt.Printf("Reverse order of %d: %b", 5, a)
  
}


Output:

Reverse order of 5: 10100000000000000000000000000000

Example 2 :




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


Output:

Reverse32(00000000000000000000000000001001) := 10010000000000000000000000000000
Reverse32(00000000000000000000000000001101) := 10110000000000000000000000000000



Contact Us