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
+15.2k Golang : Save(pipe) HTTP response into a file
+7.9k Golang Hello World Example
+24.5k Golang : GORM read from database example
+12.6k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+7.1k Golang : Get Alexa ranking data example
+4.8k Facebook : How to place save to Facebook button on your website
+30.8k Golang : Download file example
+15.2k Golang : Get timezone offset from date or timestamp
+26.9k Golang : Force your program to run with root permissions
+11.2k CodeIgniter : How to check if a session exist in PHP?
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+10.2k Golang : How to get quoted string into another string?