Technical Computer Science
Computer Number Formats
Thorsten Thormählen
October 27, 2024
Part 2, Chapter 2
Thorsten Thormählen
October 27, 2024
Part 2, Chapter 2
This is the print version of the slides.
Advance slides with the → key or
by clicking on the right border of the slide
Slides can also be advanced by clicking on the left or right border of the slide.
Type | Font | Examples |
---|---|---|
Variables (scalars) | italics | $a, b, x, y$ |
Functions | upright | $\mathrm{f}, \mathrm{g}(x), \mathrm{max}(x)$ |
Vectors | bold, elements row-wise | $\mathbf{a}, \mathbf{b}= \begin{pmatrix}x\\y\end{pmatrix} = (x, y)^\top,$ $\mathbf{B}=(x, y, z)^\top$ |
Matrices | Typewriter | $\mathtt{A}, \mathtt{B}= \begin{bmatrix}a & b\\c & d\end{bmatrix}$ |
Sets | calligraphic | $\mathcal{A}, B=\{a, b\}, b \in \mathcal{B}$ |
Number systems, Coordinate spaces | double-struck | $\mathbb{N}, \mathbb{Z}, \mathbb{R}^2, \mathbb{R}^3$ |
Bytes | Bits | Range of values | Name of the data type (Microsoft Visual C++) |
---|---|---|---|
1 | 8 | $[0;255]$ | unsigned char |
2 | 16 | $[0;65535]$ | unsigned short |
4 | 32 | $[0;4294967295]$ | unsigned int |
8 | 64 | $[0;18446744073709551615]$ | unsigned long long |
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 |
Decimal | -0 | -1 | -2 | -3 | -4 | -5 | -6 | -7 |
Binary | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 |
Decimal | -0 | -1 | -2 | -3 | -4 | -5 | -6 | -7 |
Binary | 1111 | 1110 | 1101 | 1100 | 1011 | 1010 | 1001 | 1000 |
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 |
Decimal | -1 | -2 | -3 | -4 | -5 | -6 | -7 | -8 |
Binary | 1111 | 1110 | 1101 | 1100 | 1011 | 1010 | 1001 | 1000 |
Sign $w_a$ | Sign $w_b$ | Correct result when | Overflow (incorrect result) when |
+ | + | $c_{n-1}=0$ und $c_{n-2}=0$ | $c_{n-1}=0$ und $c_{n-2}=1$ |
+ | - | $c_{n-1}= c_{n-2}$ | never |
- | + | $c_{n-1}= c_{n-2}$ | never |
- | - | $c_{n-1}=1$ und $c_{n-2}=1$ | $c_{n-1}=1$ und $c_{n-2}=0$ |
Representation | Range | One-to-one mapping | Math Operations |
---|---|---|---|
Sign-magnitude | symmetric | no | Special treatment |
Ones' complement | symmetric | no | 2-step addition |
Two's complement | asymmetric | yes | Simple |
Bytes | Bits | Range | Name of the data type (Microsoft Visual C++) |
---|---|---|---|
1 | 8 | $[–128;127]$ | char |
2 | 16 | $[–32768;32767]$ | short |
4 | 32 | $[–2147483648;2147483647]$ | int |
8 | 64 | $\begin{align} [-&9223372036854775808; \\ &9223372036854775807\ \ ] \end{align}$ | long long |
Biased exponent $c$ | Mantissa $m$ | 32-/64-bit Precision |
---|---|---|
$000\dots0000$ | arbitrary | 32: $(-1)^s 0.m \cdot 2^{-126}$ |
64: $(-1)^s 0.m \cdot 2^{-1022}$ | ||
$ 111\dots1111$ | $=0$ | $(-1)^s \cdot \infty$ |
$ 111\dots1111$ | $\ne0$ | Not a Number (NaN) |
all other bit sequences (default) | arbitrary | 32: $(-1)^s 1.m \cdot 2^{c-127}$ |
64: $(-1)^s 1.m \cdot 2^{c-1023}$ |
Bytes | Bits | Range of values | Name of data type |
---|---|---|---|
4 | 32 | ± 1.4e-45 ... 3.403e38 | float |
8 | 64 | ± 4.94e-324 ... 1.798e308 | double |
Please notify me by e-mail if you have questions, suggestions for improvement, or found typos: Contact