Use this function to get the index of the most significant (set) bit in a
Defined in [SDL_bits.h](https://github.com/libsdl-org/SDL/blob/SDL2/include/SDL_bits.h)
x |
the number to find the MSB of |
Returns the index of the most significant bit of x, or -1 if x is 0.
#include "SDL.h"
#include "SDL_bits.h"
int main(int argc, char *argv[]) {
if (argc != 2) {
SDL_Log("Usage: %s <number", argv[0]);
return 1;
}
int bitmask = SDL_atoi(argv[1]);
if (bitmask < 0) {
SDL_Log("Number must be positive");
return 1;
}
int index = SDL_MostSignificantBitIndex32(bitmask);
SDL_Log("MSB index is %d", index);
return 0;
}