BitArray
This package provides a bit array structure with sub-byte methods like packing
and shifting for arrays of bits of arbitrary length.
This is not useful for set operations. It facilitates encoding data that is not
necessarily aligned to 8 bits. It was originally designed to cater to the
packed encoding required for the ISO/IEC 20248 digital signature format.
Usage
import (
"fmt"
"src.userspace.com.au/bitarray"
)
func main() {
ba := &bitarray.BitArray{}
ba.AddBit(1)
ba.AddBit(0)
ba.AddBit(1)
fmt.Println(ba.Len())
fmt.Printf("%08b\n", ba.Bytes())
ba.Add(5)
fmt.Printf("%08b\n", ba.Bytes())
ba.AddN(5, 10)
fmt.Printf("%08b\n", ba.Bytes())
r := bitarray.NewReader(ba)
var out uint
r.ReadBits(&out, 16)
fmt.Printf("%08b\n", out)
ba.ShiftL(2)
fmt.Println(ba.String())
ba2, _ := ba.Slice(9, 6)
fmt.Println(ba2.String())
}