SDL Wiki
(This is the legacy documentation for stable SDL2, the current stable version; SDL3 is the current development version.)

SDL_MostSignificantBitIndex32

Use this function to get the index of the most significant (set) bit in a

Header File

Defined in [SDL_bits.h](https://github.com/libsdl-org/SDL/blob/SDL2/include/SDL_bits.h).

Syntax

SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x);

Function Parameters

x

the number to find the MSB of

Return Value

Returns the index of the most significant bit of x, or -1 if x is 0.

Code Examples


#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;
}

CategoryAPI, CategoryAPIFunction, CategoryBits


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.