Skip to content
UPEEC

Bitwise Operators

Operate on individual bits: AND, OR, XOR, NOT and shifts — the language of hardware registers.

Easy
Comments 0
OperatorMeaningExample (a = 0b1100, b = 0b1010)
&ANDa & b = 0b1000
|ORa | b = 0b1110
^XORa ^ b = 0b0110
~NOTinverts every bit
<<shift left1 << 3 = 0b1000
>>shift right0b1000 >> 2 = 0b0010

Shifting left by nn multiplies by 2n2^n; shifting right divides (for unsigned values).

Sub-topics (1)

Bit Masking

Set, clear, toggle and test individual bits of a register using masks.

Easy♥ 0🔖 0💬 0

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.