| Typ | Wertebereich | Länge |
| byte | -128..127 | 8 Bit |
| short | -32768..32767 | 16 Bit |
| int | -2147483648..2147483647 | 32 Bit |
| long | -9223372036854775808..9223372036854775807 | 64 Bit |
Sei
Algorithmus dezimal
dual:
while (x != 0){
if (x%2 == 0) IO.print('0');
else IO.print('1');
x = x/2;
}
Obacht: Bits werden rückwärts generiert!
Codierung der ganzen Zahlen im 2-er Komplement:
| d3 | d2 | d1 | d0 | x |
| 0 | 1 | 1 | 1 | 7 |
| 0 | 1 | 1 | 0 | 6 |
| 0 | 1 | 0 | 1 | 5 |
| 0 | 1 | 0 | 0 | 4 |
| 0 | 0 | 1 | 1 | 3 |
| 0 | 0 | 1 | 0 | 2 |
| 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | -1 |
| 1 | 1 | 1 | 0 | -2 |
| 1 | 1 | 0 | 1 | -3 |
| 1 | 1 | 0 | 0 | -4 |
| 1 | 0 | 1 | 1 | -5 |
| 1 | 0 | 1 | 0 | -6 |
| 1 | 0 | 0 | 1 | -7 |
| 1 | 0 | 0 | 0 | -8 |
Beispiel zur Berechnung des 2-er Komplements einer negativen Zahl:
| Gegeben - x | -4 |
| Finde di zu x | 0100 |
| Invertiere Bits | 1011 |
| Addiere 1 | 1100 |
Vorteil: Nur ein Addierwerk!
| 0011 | 3 |
| + 1011 | -5 |
| = 1110 | -2 |
Subtraktion mittels Negierung auf Addition zurückführen. Obacht: Überlauf beachten!
| 0111 | 7 | |
| + 0001 | 1 | |
| = 1000 | -8 | falsch |
| 00111 | 7 | 00011 | 3 | ||||
| + 00001 | 1 | 11011 | -5 | ||||
| 01000 | 11110 | -2 | |||||
| Ergebnis undefiniert | Ergebnis ok! |
| + | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | Addition |
| - | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | Subtraktion |
| * | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | Multiplikation |
| / | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | ganzzahlige Division |
| % | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | Modulo = Rest der Division |
| & | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | bitweise Und-Verknüpfung |
| | | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | bitweise Oder-Verknüpfung |
| ^ | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | bitweise XOR-Verknüpfung |
| << | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | Linksshift |
| >> | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | Vorzeichen erhaltender Rechtsshift |
| >>> | : | Ganzzahl x Ganzzahl |
|
Ganzzahl | Vorzeichen ignorierender Rechtsshift |
| ~ | : | Ganzzahl |
|
Ganzzahl | Bitweise Negation |
| - | : | Ganzzahl |
|
Ganzzahl | Vorzeichenumkehr |
| ++ | : | Ganzzahl |
|
Ganzzahl | Inkrement |
| -- | : | Ganzzahl |
|
Ganzzahl | Dekrement |
123 +123 -123
Eine führende Null kündigt eine Oktalzahl zur Basis 8 an: 0173. Eine führende Null mit nachfolgendem x oder X kündigt eine Hexadezimalzahl zur Basis 16 an: 0x7B.