Three commonly used functions when it comes to bit manipulation are :
is_pow2
: Checking that an integer is a power-of-two (only one bit is set): $00010000 \Rightarrow yes$floor_pow2
: Finds the largest integer power of two not greater than the given value $00010010 \Rightarrow 00010000$ (msb on the left, lsb on the right)ceil_pow2
: Finds the smallest integer power of two not less than the given value $00010010 \Rightarrow 00100000$ (msb on the left, lsb on the right)
However, the concept of a power of two requires to assume a numeric interpretation of sets of bits. But fundamentally the functionality provided by these functions stay valid on bitsets without a numeric interpretation. For example, what is_pow2(x)
is really asking is whether popcount(x) == 1
. And popcount
does not require to define any concept of power of two.
I was wondering if the three functions is_pow2
, floor_pow2
, ceil_pow2
had commonly accepted names in mathematics, computer science or computer engineering which do not rely on the concept of a power of two.