My current (bad) solution:
void initialization(void) {
for (unsigned int i = 0; i < pageSize; i++) {
if (2 << i == pageSize) {
offset = i;
break;
}
}
}
Example: pageSize = 4096, Solve for x in, pageSize = 2^x
I feel like there should be a much better way if doing this without a loop and without math.h
. Especially since the base is always 2 and there's a lot of stuff with bit shifting involving powers of 2.