Bitwise operation |= in C

| performs a bitwise OR on the two operands it is passed. For example, If you look at the underlying bits for 0x0A and 0x50, they are 0b00001010 and 0b01010000 respectively. When combined with the OR operator the result in b is 0b01011010, or 0x5A in hexadecimal. |= is analogous to operators like += and -= in that it will perform a bitwise OR on the two operands then store the result in … Read more

What are bitwise shift (bit-shift) operators and how do they work?

The bit shifting operators do exactly what their name implies. They shift bits. Here’s a brief (or not-so-brief) introduction to the different shift operators. The Operators >> is the arithmetic (or signed) right shift operator. >>> is the logical (or unsigned) right shift operator. << is the left shift operator, and meets the needs of … Read more

What is “2’s Complement”?

Two’s complement is a clever way of storing integers so that common math problems are very simple to implement. To understand, you have to think of the numbers in binary. It basically says, for zero, use all 0’s. for positive integers, start counting up, with a maximum of 2(number of bits – 1)-1. for negative … Read more