suou.bits

Utilities for working with bits & handy arithmetics

Functions

count_ones(n)

Count the number of one bits in a number.

join_bits(l, nbits)

Concatenate a list of integers into a bytestring.

mask_shift(n, mask)

Select the bits from n chosen by mask, least significant first.

mod_ceil(x, y)

Smallest integer greater than x and divisible by y

mod_floor(x, y)

Greatest integer smaller than x and divisible by y

split_bits(buf, nbits)

Split a bytestring into chunks of equal size, and interpret each chunk as an unsigned integer.