func (bv *BitVector) String() (s string) {
	for i := 0; i < bv.len*8; i++ {
		if bv.Get(i) {
			s += "1"
		} else {
			s += "0"
		}
	}
	return s
}
String implements Stringer interface
package bitvector
import (
	"errors"
)
var errInvalidLength = errors.New("invalid length")
type BitVector struct {
	len int
	b   []byte
}
func New(l int) (*BitVector, error) {
	return NewFromBytes(make([]byte, l/8+1), l)
}
func NewFromBytes(b []byte, l int) (*BitVector, error) {
	if l <= 0 {
		return nil, errInvalidLength
	}
	if len(b)*8 < l {
		return nil, errInvalidLength
	}
	return &BitVector{
		len: l,
		b:   b,
	}, nil
}
func (bv *BitVector) Get(i int) bool {
	bi := i / 8
	return bv.b[bi]&(0x1<<uint(i%8)) != 0
}
func (bv *BitVector) set(i int, v bool) {
	bi := i / 8
	cv := bv.Get(i)
	if cv != v {
		bv.b[bi] ^= 0x1 << uint8(i%8)
	}
}
func (bv *BitVector) Set(i int) {
	bv.set(i, true)
}
func (bv *BitVector) Unset(i int) {
	bv.set(i, false)
}
func (bv *BitVector) SetBytes(bs []byte) error {
	if len(bs) != bv.len {
		return errors.New("invalid length")
	}
	for i := 0; i < bv.len*8; i++ {
		bi := i / 8
		if bs[bi]&(0x01<<uint(i%8)) > 0 {
			bv.set(i, true)
		}
	}
	return nil
}
func (bv *BitVector) UnsetBytes(bs []byte) error {
	if len(bs) != bv.len {
		return errors.New("invalid length")
	}
	for i := 0; i < bv.len*8; i++ {
		bi := i / 8
		if bs[bi]&(0x01<<uint(i%8)) > 0 {
			bv.set(i, false)
		}
	}
	return nil
}