bits.ReverseBytes16() 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 ReverseBytes16() function which is used to find the reversed order of the value of a. To access the ReverseBytes16() function you need to add a math/bits package in your program with the help of the import keyword.
Syntax:
func ReverseBytes16(a uint16) uint16
Parameters: This function takes one parameter of uint16 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.ReverseBytes16() Function package main import ( "fmt" "math/bits" ) // Main function func main() { // Finding the reverse order of a // Using ReverseBytes16() function a := bits.ReverseBytes16(7) fmt.Printf( "Reverse order of %d: %b" , 7, a) } |
Output:
Reverse order of 7: 11100000000
Example 2:
// Golang program to illustrate // bits.ReverseBytes16() Function package main import ( "fmt" "math/bits" ) // Main function func main() { // Finding the reverse order of a // Using ReverseBytes16() function a1 := bits.ReverseBytes16(3) fmt.Printf( "ReverseBytes16(%016b) := %b\n" , 3, a1) a2 := bits.ReverseBytes16(7) fmt.Printf( "ReverseBytes16(%016b) := %b\n" , 7, a2) } |
Output:
ReverseBytes16(0000000000000011) := 1100000000 ReverseBytes16(0000000000000111) := 11100000000
Contact Us