Top "Bit-manipulation" questions

The manipulation of individual bits.

Rounding up to next power of 2

I want to write a function that returns the nearest next power of 2 number. For example if my input is 789, …

c optimization bit-manipulation
How do I get bit-by-bit data from an integer value in C?

I want to extract bits of a decimal number. For example, 7 is binary 0111, and I want to get 0 1 1 1 all bits …

c bit-manipulation
In C/C++ what's the simplest way to reverse the order of bits in a byte?

While there are multiple ways to reverse bit order in a byte, I'm curious as to what is the "simplest" …

c++ c bit-manipulation
Most common C# bitwise operations on enums

For the life of me, I can't remember how to set, delete, toggle or test a bit in a bitfield. …

c# .net enums bit-manipulation flags
Bitwise operation and usage

Consider this code: x = 1 # 0001 x << 2 # Shift left 2 bits: 0100 # Result: 4 x | 2 # Bitwise OR: 0011 # Result: 3 x & 1 # Bitwise AND: 0001 # Result: 1 …

python binary operators bit-manipulation
What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C?

If I have some integer n, and I want to know the position of the most significant bit (that is, …

c algorithm optimization bit-manipulation
Two's Complement in Python

Is there a built in function in python which will convert a binary string, for example '111111111111', to the …

python bit-manipulation twos-complement
What does a bitwise shift (left or right) do and what is it used for?

I've seen the operators >> and << in various code that I've looked at (none of which I …

bit-manipulation bitwise-operators bit-shift
Best practices for circular shift (rotate) operations in C++

Left and right shift operators (<< and >>) are already available in C++. However, I couldn't find out …

c++ c rotation bit-manipulation c++-faq
bitwise XOR of hex numbers in python

how can we XOR hex numbers in python eg. I want to xor 'ABCD' to '12EF'. answer should be …

python hex bit-manipulation xor