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)
int SDL_MostSignificantBitIndex32(Uint32 x); SDL_FORCE_INLINE
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) {
"Usage: %s <number", argv[0]);
SDL_Log(return 1;
}int bitmask = SDL_atoi(argv[1]);
if (bitmask < 0) {
"Number must be positive");
SDL_Log(return 1;
}int index = SDL_MostSignificantBitIndex32(bitmask);
"MSB index is %d", index);
SDL_Log(return 0;
}
CategoryAPI, CategoryAPIFunction, CategoryBits