AND

result = x & y;
xyresult
000
010
100
111

OR

result = x | y;
xyresult
000
011
101
111

XOR

result = x ^ y;
xyresult
000
011
101
110

NOT

result = ~x;
xresult
01
10
  • 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