Golang encoding/asn1.BitString type, At and RightAlign inner functions example
package encoding/asn1
BitString is the structure to use when you want an ASN.1 BIT STRING type. A bit string is padded up to the nearest byte in memory and the number of valid bits is recorded. Padding bits will be zero.
BitString's At function returns the bit at the given index. If the index is out of range it returns false.
BitString's RightAlign function returns a slice where the padding bits are at the beginning. The slice may share memory with the BitString.
Golang encoding/asn1.BitString type and inner functions usage example
package main
import (
"encoding/asn1"
"fmt"
)
func main() {
var bstr asn1.BitString
bstr.Bytes = []byte{0x82, 0x40}
bstr.BitLength = 16
fmt.Println(bstr.At(0))
fmt.Println(bstr.RightAlign)
}
Output :
1
0x22a0
Reference :
Advertisement
Something interesting
Tutorials
+9.7k Golang : Detect number of active displays and the display's resolution
+16.3k Golang : convert string or integer to big.Int type
+6.3k Golang : How to search a list of records or data structures
+18k Golang : Get all upper case or lower case characters from string example
+12.3k Golang : 2 dimensional array example
+7.4k Golang : Example of custom handler for Gorilla's Path usage.
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+6.1k nginx : force all pages to be SSL
+16.4k Golang : Test floating point numbers not-a-number and infinite example
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+36.7k Golang : Display float in 2 decimal points and rounding up or down