Control Keys

move to next slide (also Enter or Spacebar).
move to previous slide.
 d  enable/disable drawing on slides
 p  toggles between print and presentation view
CTRL  +  zoom in
CTRL  -  zoom out
CTRL  0  reset zoom

Slides can also be advanced by clicking on the left or right border of the slide.

Notation

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$

 

There are only 10 types of people in the world: those who understand binary, and those who don't.
Quelle: Wikipedia

Contents

  • Simple Number Representations
  • Positional Notation: B-Adic Representation
  • Rational Numbers
  • Conversion between Number Systems

Tally Marks

tallies
  • A number $x$ is represented by repeating a special character (dash, notch, bars, etc.) $x$ times
  • Tally marks systems were used very early on by mankind
  • Still frequently used today: e.g. coffee list, inventory
  • Useful when the numbers are small, but no longer applicable for large numbers
  • Addition is simple

Roman Numbers

Number symbol Value
$\mathrm{I}$ 1
$\mathrm{V}$ 5
$\mathrm{X}$ 10
$\mathrm{L}$ 50
$\mathrm{C}$ 100
$\mathrm{D}$ 500
$\mathrm{M}$ 1000

Roman Numbers

  • With Roman numerals, the relative position of the characters is important
  • Examples:
    $\mathrm{I}$ = 1 $\mathrm{X}$ = 10
    $\mathrm{II}$ = 2 $\mathrm{XI}$ = (10+1) = 11
    $\mathrm{III}$ = 3 $\mathrm{XII}$ = (10+2) = 12
    $\mathrm{IV}$ = (5-1) = 4 $\mathrm{XXXIX}$ = (30+10-1) = 39
    $\mathrm{V}$ = 5 $\mathrm{XL}$ = (50-10) = 40
    $\mathrm{VI}$ = (5+1) = 6 $\mathrm{L}$ = 50
    $\mathrm{VII}$ = (5+2) = 7 $\mathrm{LIX}$ = (50+10-1)=59
    $\mathrm{VIII}$ = (5+3) = 8 $\mathrm{LX}$ = 60
    $\mathrm{IX}$ = (10-1) = 9 $\mathrm{XC}$ = (100-10) = 90

Decimal System

  • The decimal system, which we use in everyday life, has ten number symbols:
    $\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9\}$
  • The absolute position of the characters is important to determine the numerical value
  • Example: $123 \ne 321$
  • Example: $5124 = 5 \cdot 1000 + 1 \cdot 100 + 2 \cdot 10 + 4$
  • The numerical value $w$ is computed as follows from the digits $z_{n-1}, \dots, z_1, z_0$ of a decimal number:
    $\begin{aligned}w &= z_{n-1} \cdot 1\underbrace{0\dots0}_{n-1} + \dots z_2 \cdot 100 + z_1 \cdot 10 + \ z_0 \cdot 1 =\\ &=\sum\limits_{i=0}^{n-1} z_i \cdot 10^i\end{aligned}$
  • The decimal system is a so-called positional notation
  • The decimal system is a positional notation with a base of 10

Positional Notation: B-Adic Representation

  • If $b > 1$ is any natural number ($b\in\mathbb{N}$), then the set $\{0, \dots ,b-1\}$ is the alphabet of the b-adic number system (with base $b$)
    • Decimal system:
      $b=10 \rightarrow \{0, 1, 2, 3, 4, 5, 6, 7, 8, 9\}$
    • Dual system (binary system):
      $b=2 \rightarrow \{0, 1\}$
    • Octal system:
      $b=8 \rightarrow \{0, 1, 2, 3, 4, 5, 6, 7\}$
    • Hexadecimal system:
      $b=16 \rightarrow \{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f\}$

Positional Notation: B-Adic Representation

  • As already stated, a numerical value $w$ is calculated in the decimal system as follows:
    $w = \sum\limits_{i=0}^{n-1} z_i \cdot 10^i$
  • This can be generalised. For arbitrary bases $b > 1$, the following applies:
    $w = \sum\limits_{i=0}^{n-1} z_i \cdot b^i$
    where $n$ is the number of digits in the number $w$
  • Numerical notation: $w = (z_{n-1}\dots z_2 z_1 z_0)_b$

Dual System (Binary System)

  • The base $b=2$ with an alphabet of two number symbols, $0$ and $1$, is of particular importance in computer science because two symbols can be easily encoded electrically:
    • "no current flows" typically corresponds to $0$
    • "current flows" corresponds to $1$
    • Each digit of a binary number is referred to as a "bit" ("binary digit")
    • 1 bit is therefore the smallest amount of information that can be stored
    • 8 bits are referred to as 1 byte
  • The bit sequence $(01001101)_2$ corresponds to the decimal number $(77)_{10}$
    $\begin{align}&(01001101)_2 \\ &= 0 \cdot 2^7 + 1 \cdot 2^6 + 0 \cdot 2^5 + 0 \cdot 2^4+ 1 \cdot 2^3 + 1 \cdot 2^2 + 0 \cdot 2^1 + 1 \cdot 2^0\\ &=0 \cdot 128 + 1 \cdot 64 + 0 \cdot32 + 0 \cdot 16+ 1 \cdot 8 + 1 \cdot 4 + 0 \cdot 2 + 1 \cdot 1\\ &=64 + 8 + 4 + 1\\ &=77 \end{align}$

Octal and Hexadecimal System

  • Octal system:
    • $(115)_8$ corresponds to the decimal number $(77)_{10}$
      $\begin{align}(115)_8 &= 1 \cdot 8^2 + 1 \cdot 8^1 + 5 \cdot 8^0\\ &=1 \cdot 64 + 1 \cdot 8 + 5 \cdot 1\\ &=77 \end{align}$
  • Hexadecimal system:
    • $(4D)_{16}$ corresponds to the decimal number $(77)_{10}$
      $\begin{align}(4D)_{16} &= 4 \cdot 16^1 + D \cdot 16^0\\ &=64 + 13\\ &=77 \end{align}$

Positional Systems with Different Bases

  • This is an interactive counter. Click on the counter to increase the number:

  • Different bases can be selected:

    Base (top):       Base (bottom):

  • Observation: Small bases require a smaller alphabet, but more digits

 

There are 10 kinds of people in the world: those that understand binary, those that don't, and those that didn't expect this joke to be in ternary.
Source: Wikipedia

Quiz

  • Question: The number $(1220)_{3}$ in the ternary system is to be converted into the decimal system. What is the result?
    • Answer 1: 51
    • Answer 2: 17
    • Answer 3: 24
    • Answer 4: 49
    • Answer 5: no idea
Take part in the online quiz by visiting the website:
www.onlineclicker.org

Rational Numbers

  • A rational number $w \in \mathbb{Q}$ can also be specified in the b-adic representation
  • For this purpose, the fractional part is represented by negative exponents
  • Example from the decimal system, which we are familiar with:
    $913,64 = 9 \cdot 10^2 + 1 \cdot 10^1 + 3 \cdot 10^0 + 6 \cdot 10^{-1} + 4 \cdot 10^{-2}$
  • This can be generalized again:
    $\begin{align} w &= (z_{n-1}\dots z_2 z_1 z_0, z_{-1} \dots z_{-m})_b\\ &= \sum\limits_{i=-m}^{n-1} z_i \cdot b^i \end{align}$
    where $n$ indicates the number of digits before the decimal point
    and $m$ indicates the number of digits after the decimal point
  • Example in the binary system:
    $\begin{align}(11,101)_2 &= 1 \cdot 2^1 + 1 \cdot 2^0 + 1 \cdot 2^{-1} + 0 \cdot 2^{-2} + 1 \cdot 2^{-3} \\ &= 2 + 1 + 0.5 + 0,125 = (3,625)_{10}\end{align}$

Metric Prefixes

  • For many powers of ten, there are standardized metric prefixes that can be placed before the actual physical units, e.g. 1000 m = 1 km
$10^1 $ $10^2 $ $10^3 $ $10^6 $ $10^9 $ $10^{12}$ $10^{15}$ $10^{18}$ $10^{21}$ $10^{24}$
deca hecto kilo mega giga tera peta exa zetta yotta
da h k M G T P E Z Y
$10^{-1}$ $10^{-2} $ $10^{-3} $ $10^{-6} $ $10^{-9} $ $10^{-12}$ $10^{-15}$ $10^{-18}$ $10^{-21}$ $10^{-24}$
deci centi milli micro nano pico femto atto zepto yocto
d c m µ n p f a z y
Source: Wikipedia

Binary Prefixes

  • When talking about 1 kByte (kilobyte) in computer science, this does not always refer to 1000 bytes, but often to 1024 bytes. This leads to confusion. Therefore, it would be better to use the following IEC-specified prefixes for the powers of 1024:
Name Prefix Value
kibi Ki $2^{10} = 1024^{1} =1.024$
mebi Mi $2^{20} =1024^{2} =1.048.576$
gibi Gi $2^{30} =1024^{3} =1.073.741.824$
tebi Ti $2^{40} =1024^{4} =1.099.511.627.776$
pebi Pi $2^{50} =1024^{5} =1.125.899.906.842.624$
exbi Ei $2^{60} =1024^{6} =1.152.921.504.606.846.976$
zebi Zi $2^{70} =1024^{7} =1.180.591.620.717.411.303.424$
yobi Yi $2^{80} =1024^{8} =1.208.925.819.614.629.174.706.176$
Source: Wikipedia

Conversion between Number Systems

  • To develop an algorithm for converting between number systems, let us consider what happens when we divide the formula for the b-adic representation by the base $b$:
    $\begin{aligned}w = \sum\limits_{i=0}^{n-1} z_i \cdot b^i\Leftrightarrow \frac{w}{b} &= \frac{1}{b}\sum\limits_{i=0}^{n-1} z_i \cdot b^i\\ &= \underbrace{\left(\sum\limits_{i=0}^{n-2} z_{i+1} \cdot b^i\right)}_{s_1} + \frac{z_0}{b} \end{aligned}$
  • The first term $s_1$ is the integer result of the division and $z_0$ is the remainder of the division
  • This showed that the last digit $z_0$ can be calculated from the remainder of the division with the target base $b$
  • The integer result of the division represents the numerical value of the remaining digits (without $z_0$). All target digits can be determined by recursive application.

Conversion between Number Systems

  • Example: Converting the decimal number 6485 to binary:
6485 / 2 = 3242  remainder 1
3242 / 2 = 1621  remainder 0
1621 / 2 =  810  remainder 1
 810 / 2 =  405  remainder 0
 405 / 2 =  202  remainder 1
 202 / 2 =  101  remainder 0
 101 / 2 =   50  remainder 1
  50 / 2 =   25  remainder 0
  25 / 2 =   12  remainder 1
  12 / 2 =    6  remainder 0
   6 / 2 =    3  remainder 0
   3 / 2 =    1  remainder 1
   1 / 2 =    0  remainder 1
  • The algorithm terminates if the result of the division is equal to zero
  • The binary number can be read from bottom to top using the remainders: $(1100101010101)_2$
  • Note: If such an algorithm has to be implemented, the remainder of the division can be computed using the modulo operation: 6485 mod 2 = 1

Conversion between Number Systems

  • Example: Converting the decimal number 23521 to the hexadecimal system:
 23521 / 16 =  1470  Rest  1 (1)
  1470 / 16 =    91  Rest 14 (E)
    91 / 16 =     5  Rest 11 (B)
     5 / 16 =     0  Rest  5 (5)
  • The result can be read off again from the remainders: $(5BE1)_{16}$

Conversion between Number Systems

  • Example: Conversion of $(360)_7$ into the quinary system (base 5)
  • First, $(360)_7$ must be converted to decimal:
    $(360)_7 = 3 \cdot 49 + 6 \cdot 7 + 0 \cdot 1 = (189)_{10}$
  • Then we convert $189_{10}$ into the quinary system:
189 / 5 =  37  Rest 4
 37 / 5 =   7  Rest 2
  7 / 5 =   1  Rest 2
  1 / 5 =   0  Rest 1
  • The result can be read off again from the remainders: $(1224)_{5}$
  • Instead of taking the detour via the decimal system, we could theoretically apply the procedure directly in the 7-based system. However, then we would have to perform the operations (division and calculation of the remainder) in the 7-based system, which we as humans are not used to.

Conversion between Binary and Hexadecimal Notation

  • 4 bits corresponds to exactly one hexadecimal digit
0000 = 0 0100 = 4 1000 = 8 1100 = C
0001 = 1 0101 = 5 1001 = 9 1101 = D
0010 = 2 0110 = 6 1010 = A 1110 = E
0011 = 3 0111 = 7 1011 = B 1111 = F
  • This allows the conversion of a binary number to be read directly from the block of 4 bits: $(1101~0001~1110~1111)_2 = (D1EF)_{16}$
  • The hexadecimal notation is therefore particularly useful for displaying a bit sequence in a clear and compact way
  • It is similarly easy to convert a binary number into other systems with a base $b=2^k$, such as 4 or 8

 

If only dead people understand hexadecimal, how many people understand hexadecimal?

$\begin{align}(DEAD)_{16} = &13 \cdot 16^3 + 14 \cdot 16^2 \\ &+ 10 \cdot 16^1 + 13 \cdot 16^0 = (57005)_{10}\end{align}$

Conversion for Rational Numbers

  • To convert rational numbers, we consider the integer and fractional parts separately:
    $\begin{align} w &= (z_{n-1}\dots z_2 z_1 z_0, z_{-1} \dots z_{-m})_b\\ &= \sum\limits_{i=-m}^{n-1} z_i \cdot b^i \\ &= \left(\sum\limits_{i=0}^{n-1} z_i \cdot b^i\right) + \left(\sum\limits_{i=-m}^{-1} z_i \cdot b^i\right)\end{align}$
  • The conversion for the integer part is known, so we now only consider the fractional part $\tilde{w}$:
    $\begin{align} \tilde{w} &= (0, z_{-1} \dots z_{-m})_b = \left(\sum\limits_{i=-m}^{-1} z_i \cdot b^i\right)\end{align}$

Conversion for Rational Numbers

  • In contrast to the approach used for the conversion of the integer part (the remainder of the division), the fractional part must be multiplied by the base $b$:
    $\begin{aligned}\tilde{w}= \sum\limits_{i=-m}^{-1} z_i \cdot b^i \Leftrightarrow \tilde{w} \cdot b &= b \sum\limits_{i=-m}^{-1} z_i \cdot b^i\\ &= \left(\sum\limits_{i=-m}^{-2} z_{i} \cdot b^{i+1}\right) + z_{-1} \end{aligned}$
  • The term $z_{-1}$ is the only part that can be $\ge 1$. Thus, the integer part of $\tilde{w} \cdot b$ is equal to $z_{-1}$
  • The fractional part of $\tilde{w} \cdot b$ represents the numerical value of the remaining digits (without $z_{-1})$. All other digits can be determined by recursive application.

Conversion for Rational Numbers

  • Example: Converting the decimal number 0.6875 into binary:
0,6875 * 2 = 1.375
0,375  * 2 = 0.75
0,75   * 2 = 1.5
0,5    * 2 = 1.0
  • The result can be read from the integer part before the decimal point from top to bottom: $(0.1011)_2$
  • The algorithm terminates when the fractional part is equal to zero

Conversion for Rational Numbers

  • Example: Converting the decimal number 0.1 into binary:
0,1 * 2 = 0.2
0,2 * 2 = 0.4
0,4 * 2 = 0.8
0,8 * 2 = 1.6
0,6 * 2 = 1.2
0,2 * 2 = 0.4
0,4 * 2 = ...
  • The algorithm never terminates
  • The fractional part is therefore periodic in binary, although it is not in decimal
  • When rounding to a finite number of digits, rounding errors occur

Conversion for Rational Numbers

  • Rounding errors during conversion to binary must always be taken into account when developing software and hardware
  • Otherwise, the system might behave in a way that is contrary to expectations
  • Example:
double a = 0.1;
double b = a * 3;
if(a == 0.1) print("This is ");
if(b == 0.3) print("no"); else print("a");
print(" round-off error\n");

Are there any questions?

questions

Please notify me by e-mail if you have questions, suggestions for improvement, or found typos: Contact

More lecture slides

Slides in German (Folien auf Deutsch)