Top "Bit-manipulation" questions

The manipulation of individual bits.

Bitwise operations and shifts

Im having some trouble understanding how and why this code works the way it does. My partner in this assignment …

c bit-manipulation bitwise-operators twos-complement bit-shift
Computing the Parity

I don't fully understand this algorithm of calculating the parity bit. Can someone please explain in detail? The following code …

bit-manipulation parity bitwise-xor
Saturating subtract/add for unsigned bytes

Imagine I have two unsigned bytes b and x. I need to calculate bsub as b - x and badd …

c++ c optimization bit-manipulation saturation-arithmetic
Count leading zeroes in an Int32

How do I count the leading zeroes in an Int32? So what I want to do is write a function …

c# count int bit-manipulation leading-zero
Java storing two ints in a long

I want to store two ints in a long (instead of having to create a new Point object every time). …

java bit-manipulation primitive
Converting rgba values into one integer in Javascript

I can already convert 32bit integers into their rgba values like this: pixelData[i] = { red: pixelValue >> 24 & 0xFF, …

javascript bit-manipulation boolean-logic
Append Enum Flags to a Parameter in a Loop (Bitwise Appending)

In C#, I am trying to "add" values to a parameter that accepts enumerated flags. I can do it on …

c# bit-manipulation enum-flags
How to mix two int colors correctly

I'm trying to blend two colors that are coded as integers. Here is my little function: int blend (int a, …

java colors int bit-manipulation color-blending
How to reverse a bitwise OR operation?

Here's what I've done: 93 | 199 which returns 223 I understand that this is because 0b1011101 | 0b11000111 is 0b11011111 However, suppose I want …

python bit-manipulation bitwise-operators bitwise-or
Enums - All options value

Is there a way to add an "All values" option to an enum without having to change its value every …

c# enums bit-manipulation flags