Bitwise operation
Jump to navigation
Jump to search
Bitwise operations
In general there are 4 basic bitwise operations for binary numbers. In bitwise operations each bit is handled separately from all other bits.
- NOT
- This unary operator (=1 operand) is a sign operator and inverts each bit of the number.
- AND
- This is a binary operator (binary means here: 2 operands). A resulting bit is 1, if both operands are also 1.
- OR
- This is a binary operator. A resulting bit is 1, if at least one of the operands is 1 (inclusive OR).
- EOR or XOR
- This is a binary operator. A resulting bit is 1, if exact one of the operands is 1 (exclusive OR).
A | B | NOT A ~A |
NOT B ~B |
A AND B A & B |
A OR B A | B |
A EOR B A ^ B |
---|---|---|---|---|---|---|
0 | 0 | 1 | 1 | 0 | 0 | 0 |
0 | 1 | 1 | 0 | 0 | 1 | 1 |
1 | 0 | 0 | 1 | 0 | 1 | 1 |
1 | 1 | 0 | 0 | 1 | 1 | 0 |
Operands
Whenever bitwise operations are done, the operands are displayed as binary, octal or hexadecimal numbers, because they allow to see the bits directly. Please use decimal or hexadecimal numbers only in this wiki.