GCC has __builtin_clz
that translates to BSR on x86/x64, CLZ on ARM, etc. and emulates the instruction if the hardware does not implement it.
Visual C++ 2005 and up has _BitScanReverse
.
More Related Contents:
- Efficient Algorithm for Bit Reversal (from MSB->LSB to LSB->MSB) in C
- Arithmetic bit-shift on a signed integer
- Are the shift operators () arithmetic or logical in C?
- What is Bit Masking?
- Rounding up to next power of 2
- Fast computing of log2 for 64-bit integers
- Extracting bits with a single multiplication
- SIMD signed with unsigned multiplication for 64-bit * 64-bit to 128-bit
- Bitwise operators and “endianness”
- Explain this snippet which finds the maximum of two integers without using if-else or any other comparison operator?
- Bitfield manipulation in C
- Casting float to int (bitwise) in C
- What does the statement if (counter & (1
- Compute fast log base 2 ceiling
- Finding consecutive bit string of 1 or 0
- Bitshift and integer promotion?
- Unexpected C/C++ bitwise shift operators outcome
- Bit twiddling: which bit is set?
- Encoding int value as an IEEE-754 float (binary32)
- C reverse bits in unsigned integer
- How to define and work with an array of bits in C?
- Implementing Logical Right Shift in C
- How do I get bit-by-bit data from an integer value in C?
- Algorithm to generate bit mask
- How does this bitwise operation check for a power of 2?
- Check if a number is non zero using bitwise operators in C
- Decimal to Binary
- C Programming – XOR Bitwise Operation
- Size of pid_t, uid_t, gid_t on Linux
- Order of fields when using a bit field in C