AND
result = x & y;| x | y | result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR
result = x | y;| x | y | result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
XOR
result = x ^ y;| x | y | result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NOT
result = ~x;| x | result |
|---|---|
| 0 | 1 |
| 1 | 0 |
- Nur 1-er Komplement, für 2-er Komplement muss noch +1 addiert werden:
x = 12; ~x; // -13 ~(x+1); // -12
Rechtsverschiebung
- Verschiebt die Bits um die angegebene Anzahl nach rechts
x 0001 0010 0011 0100 x >> 8 0000 0000 0001 0010 - Wenn das Bit genz links eine 0 ist, werden 0en von links aufgeschoben, wenn es eine 1 ist, dann 1en (Compilerabhängig)
- Entspricht einer Division mit 2
Linksverschiebung
- Verschiebt die Bits um die angegebene Anzahl nach links
x 0001 0010 0011 0100 x << 8 0011 0100 0000 0000 - Rechts werden 0en nachgeschoben