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 ReverseBytes32() function which is used to find the reversed order of the value of a. To access the ReverseBytes32() function you need to add a math/bits package in your program with the help of the import keyword.
Syntax:
func ReverseBytes32(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:
package main
import (
"fmt"
"math/bits"
)
func main() {
a := bits.ReverseBytes32(7)
fmt.Printf( "Reverse order of %d: %b" , 7, a)
}
|
Output:
Reverse order of 7: 111000000000000000000000000
Example 2:
package main
import (
"fmt"
"math/bits"
)
func main() {
a1 := bits.ReverseBytes32(3)
fmt.Printf( "ReverseBytes32(%032b) := %b\n" , 3, a1)
a2 := bits.ReverseBytes32(9)
fmt.Printf( "ReverseBytes32(%032b) := %b\n" , 9, a2)
}
|
Output:
ReverseBytes32(00000000000000000000000000000011) := 11000000000000000000000000
ReverseBytes32(00000000000000000000000000001001) := 1001000000000000000000000000
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
28 Apr, 2020
Like Article
Save Article