Exemple #1
0
func ReadUint(r *bit.Reader) uint {
	nbits := uint(0)
	zero, err := r.ReadBit(), r.Error()
	for err == nil && zero == 0 {
		nbits += 1
		zero, err = r.ReadBit(), r.Error()
	}

	if nbits == 0 || err != nil {
		return 0
	}

	x := r.ReadBits(nbits - 1)
	x = x<<1 | 1
	x = bit.Reverse(x, nbits)
	return uint(x)
}
Exemple #2
0
func ReadInt(r *bit.Reader) int {
	nbits := uint(0)

	zero, err := r.ReadBit(), r.Error()
	for err == nil && zero == 0 {
		nbits += 1
		zero, err = r.ReadBit(), r.Error()
	}

	if nbits == 0 || err != nil {
		return 0
	}

	x := r.ReadBits(nbits - 1)
	x = x<<1 | 1
	x = bit.Reverse(x, nbits)

	sign := r.ReadBit()
	v := int(x)
	if sign == 1 {
		v = -v
	}

	return v
}