Beispiel #1
0
func WriteUint(w *bit.Writer, v uint) {
	if v == 0 {
		w.WriteBit(1)
		return
	}

	nbits := bit.ScanRight(uint64(v)) + 1

	w.WriteBits(0, nbits)
	rbits := bit.Reverse(uint64(v), nbits)
	w.WriteBits(rbits, nbits)
}
Beispiel #2
0
func WriteInt(w *bit.Writer, v int) {
	if v == 0 {
		w.WriteBit(1)
		return
	}

	sign := 0
	if v < 0 {
		sign = 1
		v = -v
	}

	nbits := bit.ScanRight(uint64(v)) + 1

	w.WriteBits(0, nbits)
	rbits := bit.Reverse(uint64(v), nbits)
	w.WriteBits(rbits, nbits)
	w.WriteBit(sign)
}