122 static void testReverseNBits(
unsigned x,
unsigned n,
unsigned expected)
129 testReverseNBits(0x0, 4, 0x0);
130 testReverseNBits(0x1, 4, 0x8);
131 testReverseNBits(0x2, 4, 0x4);
132 testReverseNBits(0x3, 4, 0xC);
133 testReverseNBits(0x4, 4, 0x2);
134 testReverseNBits(0x8, 4, 0x1);
135 testReverseNBits(0x6, 4, 0x6);
136 testReverseNBits(0xE, 4, 0x7);
137 testReverseNBits(0xF, 4, 0xF);
138 testReverseNBits(0x00012345, 22, 0x0028B120);
139 testReverseNBits(0x0010000F, 32, 0xF0000800);
142 static void testReverseByte(uint8_t
x, uint8_t expected)
152 testReverseByte(0x00, 0x00);
153 testReverseByte(0x01, 0x80);
154 testReverseByte(0x02, 0x40);
155 testReverseByte(0x07, 0xE0);
156 testReverseByte(0x12, 0x48);
157 testReverseByte(0x73, 0xCE);
158 testReverseByte(0x7F, 0xFE);
159 testReverseByte(0x8C, 0x31);
160 testReverseByte(0xAB, 0xD5);
161 testReverseByte(0xE4, 0x27);
162 testReverseByte(0xF0, 0x0F);
TEST_CASE("Math::log2p1")
constexpr unsigned reverseNBits(unsigned x, unsigned bits)
Reverse the lower N bits of a given value.
constexpr T floodRight(T x) noexcept
Returns the smallest number of the form 2^n-1 that is greater or equal to the given number.
constexpr T ceil2(T x) noexcept
Returns the smallest number that is both >=a and a power of two.
uint8_t clipIntToByte(int x)
Clip x to range [0,255].
constexpr T log2p1(T x) noexcept
Returns the number of bits needed to store the value 'x', that is: for x==0 : 0 for x!...
constexpr unsigned countLeadingZeros(unsigned x)
Count the number of leading zero-bits in the given word.
constexpr uint8_t reverseByte(uint8_t a)
Reverse the bits in a byte.
constexpr bool ispow2(T x) noexcept
Is the given number an integral power of two? That is, does it have exactly one 1-bit in binary repre...
int16_t clipIntToShort(int x)
Clip x to range [-32768,32767].
constexpr KeyMatrixPosition x
Keyboard bindings.