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
+13.4k Golang : Verify token from Google Authenticator App
+7k Golang : Levenshtein distance example
+13.7k Golang : Image to ASCII art example
+12.1k Golang : Perform sanity checks on filename example
+21.8k Golang : Convert string slice to struct and access with reflect example
+4.9k Python : Find out the variable type and determine the type with simple test
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+20.9k PHP : Convert(cast) int to double/float
+8.8k Android Studio : Image button and button example
+5.5k Golang : Display advertisement images or strings on random order
+4.7k Linux/MacOSX : How to symlink a file?
+6.9k Golang : Fibonacci number generator examples