Bitmanipulation für Anfänger: Difference between revisions

From Wurst-Wasser.net
Jump to navigation Jump to search
Line 15: Line 15:
** hat 4 Byte (32 Bit)
** hat 4 Byte (32 Bit)
** kann 4.294.967.296 Werte annehmen: −2.147.483.648 bis 2.147.483.647
** kann 4.294.967.296 Werte annehmen: −2.147.483.648 bis 2.147.483.647
** Beispiel: <tt>0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0</tt> ist der Wert 0
** Beispiele
** Beispiel: <tt>0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1</tt> ist der Wert 1
*** <tt>0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0</tt> ist der Wert 0
** Beispiel: <tt>0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 1</tt> ist der Wert 256
*** <tt>0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1</tt> ist der Wert 1
** Beispiel: <tt>0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0</tt> ist der Wert 65.536
*** <tt>0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 1</tt> ist der Wert 256
** Beispiel: <tt>0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0</tt> ist der Wert 16.777.216
*** <tt>0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0</tt> ist der Wert 65.536
** Beispiel: <tt>0 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1</tt> ist der Wert 2.147.483.647
*** <tt>0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0</tt> ist der Wert 16.777.216
*** <tt>0 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1</tt> ist der Wert 2.147.483.647
<!-- ** Beispiel: <tt>1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1</tt> ist der Wert −2.147.483.648 (Das vorderste Bit (Das MSB) ist das Vorzeichen-Bit!) -->
<!-- ** Beispiel: <tt>1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1</tt> ist der Wert −2.147.483.648 (Das vorderste Bit (Das MSB) ist das Vorzeichen-Bit!) -->



Revision as of 18:20, 9 June 2013

Von Bits und Bytes

Daten-Typen (Variablen-Typen)

  • 1 Bit ist die kleinste Einheit
    • 1 Bit kann nur 2 Werte annehmen: 0 oder 1 (false oder true)
    • Beispiel: 0
    • Beispiel: 1
  • 1 Byte...
    • ...hat 8 Bit
    • ein Byte kann 256 (2 hoch 7) Werte annehmen: 0 bis 255
    • Beispiel: 0 0 0 0 0 0 0 0 ist der Wert 0
    • Beispiel: 1 0 0 0 0 0 0 0 ist der Wert 128
    • Beispiel: 1 0 0 0 0 0 0 1 ist der Wert 129
    • Beispiel: 1 1 1 1 1 1 1 1 ist der Wert 255
  • 1 Integer[1]
    • hat 4 Byte (32 Bit)
    • kann 4.294.967.296 Werte annehmen: −2.147.483.648 bis 2.147.483.647
    • Beispiele
      • 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 ist der Wert 0
      • 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1 ist der Wert 1
      • 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 1 ist der Wert 256
      • 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 ist der Wert 65.536
      • 0 0 0 0 0 0 0 1 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 ist der Wert 16.777.216
      • 0 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 ist der Wert 2.147.483.647

Über die Bits eines Bytes oder Integers

  • Das rechteste Bit eines Bytes oder Integer nennt man das LeastSignificantBit[2].
  • Das rechteste Bit eines Bytes oder Integer nennt man das MostSignificantBit[3].

Bit-Shifts

  • SHL verschiebt die Bits eines Bytes oder Integers nach links
    • Beispiele:
var a: integer;
[...]
a:=1; // Dann ist da

Boolsche Algebra


  1. wir meinen Signed-32-Bit Integer, 8-, 16- und 64-Bit-Integer und unsigned lassen wir mal weg :)
  2. auch LSB genannt
  3. auch MSB genannt