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
+10k CodeIgniter : Load different view for mobile devices
+6.9k Golang : Pat multiplexer routing example
+8.2k Golang : Qt splash screen with delay example
+5.2k Golang : The Tao of importing package
+20.2k Golang : Compare floating-point numbers
+20.6k Golang : Secure(TLS) connection between server and client
+24.6k Golang : How to validate URL the right way
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+7.5k Golang : Shuffle strings array
+8.5k Golang : How to check variable or object type during runtime?
+11.5k CodeIgniter : Import Linkedin data
+37.7k Golang : Comparing date or timestamp