previous | start | next

Bit Operation FAQs

The bit operators have some properties that may be useful for the datalab where you are only allowed to use a small subset of operators to compute required values.

Here are some properties where x is assumed to be of type int (that is, a signed integer) of size 32 bits.

Expression =
0 ^ x x
(~0) ^ x ~x
x >> 31 0 if x >= 0, and ~0 if x < 0
if x == y what is x ^ y 0
When is !!x == x Only if x = 0 or x = 1
(x >> 31) ^ x x if x >= 0; ~x if x < 0


previous | start | next