/*
Returns how many bits are required to store bits, interpreted as an
unsigned value.
NOTE: This method returns at least 1.
*/
969295
func UnsignedBitsRequired(bits int64) int {
	if bits == 0 {
		return 1
	}
	n := uint64(bits)
	ans := 0
	for n != 0 {
		n >>= 1
		ans++
	}
	return ans
}
702549
func totalUvarintBytes(a, b, c, d, e uint64, more []uint64) (n int) {
	n = numUvarintBytes(a)
	n += numUvarintBytes(b)
	n += numUvarintBytes(c)
	n += numUvarintBytes(d)
	n += numUvarintBytes(e)
	for _, v := range more {
		n += numUvarintBytes(v)
	}
	return n
}
403143
func (ec *Envcfg) GetUint64(key string, base, bitSize int) uint64 {
	u, _ := strconv.ParseUint(ec.GetKey(key), base, bitSize)
	return u
}
559878
func (b *buf) Int() int64 {
	ux, bits := b.Varint()
	x := int64(ux)
	if x&(1<<(bits-1)) != 0 {
		x |= -1 << bits
	}
	return x
}
1040808
func asn1BitLength(bitString []byte) int {
	bitLen := len(bitString) * 8

	for i := range bitString {
		b := bitString[len(bitString)-i-1]

		for bit := uint(0); bit < 8; bit++ {
			if (b>>bit)&1 == 1 {
				return bitLen
			}
			bitLen--
		}
	}

	return 0
}
135602
func (b *Bitmap) Bit(index int) bool {
	byteIndex := index / 8
	bitMask := byte(1 << (uint(index) & 0x7))
	return b.data[byteIndex]&bitMask > 0
}
733747
func (b *Bitmap) Get(index, length uint) (Block, error) {
	if index >= uint(b.size) {
		return 0, errors.New("bits: index out of range")
	}

	// I can't think of a reasonable use case for explicitly reading zero bits,
	// but returning an empty Block should be the result. Perhaps there is
	// behavior will simplify a caller's logic in some edge case.
	if length == 0 {
		return 0, nil
	}

	if length > bitsPerBlock {
		return 0, errors.New("bits: length out of range, [0-64]")
	}

	if index+length-1 >= uint(b.size) {
		return 0, errors.New("bits: length extends beyond range")
	}

	// This is the index of the internal block where the range begins.
	var storeIndex = index / bitsPerBlock

	// This is the index of the last bit relative to the internal block where
	// the range begins.
	var endBitIndex = index%bitsPerBlock + length - 1

	// Bit shift and merge the internal blocks containing the range.
	var buf Block
	if endBitIndex < bitsPerBlock {
		buf = b.store[storeIndex] >> (bitsPerBlock - endBitIndex - 1)
	} else {
		var overflow = endBitIndex - bitsPerBlock + 1
		buf = (b.store[storeIndex] << overflow) | (b.store[storeIndex+1] >> (bitsPerBlock - overflow))
	}

	var mask Block = 0xFFFFFFFFFFFFFFFF >> (bitsPerBlock - length)
	return Block(buf & mask), nil
}
931074
func ReadBits(bigint *big.Int, buf []byte) {
	i := len(buf)
	for _, d := range bigint.Bits() {
		for j := 0; j < wordBytes && i > 0; j++ {
			i--
			buf[i] = byte(d)
			d >>= 8
		}
	}
}
554938
func Uint32toUint24Bytes(n uint32) []byte {
	bytes := make([]byte, 3)
	bytes[0] = byte(n >> 16)
	bytes[1] = byte(n >> 8)
	bytes[2] = byte(n >> 0)

	return bytes
}
125774
func (b *bitReader) getBits(n uint8) uint16 {
	if n == 0 || b.bitsRead >= 64 {
		return 0
	}
	return b.getBitsFast(n)
}
663778
func (i Int) Uint64() (_ uint64, ok bool) {
	x, acc := bigintToUint64(i.bigint)
	if acc != big.Exact {
		return // inexact
	}
	return x, true
}
1274320
func (s *Subnet) Bits() (ones int, zeros int) {
	for _, b := range []byte(s.mask) {
		for i := uint(0); i < 8; i++ {
			if b&(1<<i) == 0 {
				zeros++
			} else {
				ones++
			}
		}
	}
	return
}
146584
func sm2P256GetBit(scalar *[32]uint8, bit uint) uint32 {
	return uint32(((scalar[bit>>3]) >> (bit & 7)) & 1)
}
1039107
func (b *BitReader) ReadBits(nbits int) (uint64, error) {

	var u uint64

	for nbits >= 8 {
		byt, err := b.ReadByte()
		if err != nil {
			return 0, err
		}

		u = (u << 8) | uint64(byt)
		nbits -= 8
	}

	var err error
	for nbits > 0 && err != io.EOF {
		byt, err := b.ReadBit()
		if err != nil {
			return 0, err
		}
		u <<= 1
		if byt {
			u |= 1
		}
		nbits--
	}

	return u, nil
}
189440
func CountBitsUintPopCnt(x uint) int {
	if strconv.IntSize == 64 {
		return CountBitsUint64PopCnt(uint64(x))
	} else if strconv.IntSize == 32 {
		return CountBitsUint32PopCnt(uint32(x))
	}
	panic("strconv.IntSize must be 32 or 64")
}
454463
func BitsPerPixel(format uint32) int {
	return int(C.bitsPerPixel(C.Uint32(format)))
}
1302850
func (c *Counter) Value() float64 {
	return math.Float64frombits(atomic.LoadUint64(&c.bits))
}