bits.Reverse16() Function in Golang with Examples
Last Updated :
19 Apr, 2020
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 Reverse16() function which is used to find the reversed order of the value of a. To access Reverse16() function you need to add a math/bits package in your program with the help of the import keyword.
Syntax:
func Reverse16(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 :
package main
import (
"fmt"
"math/bits"
)
func main() {
a := bits.Reverse16(5)
fmt.Printf( "Reverse order of %d: %b" , 5, a)
}
|
Output:
Reverse order of 5: 1010000000000000
Example 2 :
package main
import (
"fmt"
"math/bits"
)
func main() {
a1 := bits.Reverse16(9)
fmt.Printf( "Reverse16(%016b) := %b\n" , 9, a1)
a2 := bits.Reverse16(13)
fmt.Printf( "Reverse16(%016b) := %b\n" , 13, a2)
}
|
Output:
Reverse16(0000000000001001) := 1001000000000000
Reverse16(0000000000001101) := 1011000000000000
Share your thoughts in the comments
Please Login to comment...