Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Kommazahlen

Natürlich kann man mit Binär ebenfalls Kommazahlen abbilden.

Festkommazahlen

  • Zahlen vor und nach den Komma sind getrennt, 123,456 -> 123 & 456
  • Position des Kommas festgelegt
    • 9,87654321 (große Genauigkeit)
    • 98765432,1 (kleine Genauigkeit)
    • 98765,4321 (Mischung)
  • nicht praktisch

Gleitkommazahlen

  • Rationale und reelle Zahlen
  • keine fixe Stellen vor und nach dem Komma
  • Berechnung aufwendiger
  • Hardware: Floating Point Unit (FPU)
  • IEEE754: Ein Standard für Gleitkommazahlen

Darstellung nach IEEE754

  • Binäre Form besteht aus: Vorzeichen + Exponent + Mantisse

Einfache Genauigkeit (Single Precision) – 32-Bit

Linie aus Balken die zeigt, wie ein 32-Bit Float aufgebaut ist

Doppelte Genauigkeit (Double Precision) – 64-Bit

Linie aus Balken die zeigt, wie ein 64-Bit Float aufgebaut ist

IEEE754 Binärzahl -> Dezimal

  • Bias: fester Korrekturwert, der vom Exponent abgezogen wird.
    • \(127\) bei 32-Bit
    • \(1023\) bei 64-Bit

\( (-1)^{\color{#4493f8}{\text{Vorzeichen}}} \cdot (1 \cdot 2^0 + \color{#08ae08}{\text{Mantisse}}) \cdot \text{Basis}^{(\color{#ff8e00}{\text{Exponent}} - \color{#d91b29}{\text{Bias}})} \)

Beispiel (32-Bit)

\(\color{#4493f8}{0} \color{#ff8e00}{10000000} \color{#08ae08}{11000000000000000000000}_2\)

\( (-1)^{\color{#4493f8}{\text{0}}} \cdot (1 \cdot 2^0 + \color{#08ae08}{1} \cdot 2^{-1} + \color{#08ae08}{1} \cdot 2^{-2}) \cdot 2^{(\color{#ff8e00}{128} - \color{#d91b29}{127})} = \text{3,5}_{10} \)

Dezimal -> IEEE754 Binärzahl

Beispielzahl: \( \text{10,}25_{10} \)

  1. Vorzeichen bestimmen: \(0\)
  2. Vorkommazahl umrechnen:
    \( 10 : 2 = 5 \text{ (0)} \)
    \( 5 : 2 = 2\text{,5 (1)} \)
    \( 2 : 2 = 1\text{ (0)} \)
    \( 1 : 2 = 0\text{,5}\text{ (1)} \ \ \ \ \ \ \ \ \big\uparrow \)
    \( \rightarrow 1010_2 \)
  3. Nachkommazahl umrechnen:
    \(0\text{,25} \cdot 2 = 0\text{,5 (0)} \ \ \ \ \big\downarrow \)
    \(0\text{,5} \cdot 2 = 1\text{ (1)} \)
    \( \rightarrow 01_2 \)
  4. VK und NK kombinieren: \( 1010_2 \text{ und } 01_2 = 1010\text{,01}_2 \)
  5. Zahl “normalisieren”: \(1010\text{,01}_2 \cdot 10^{\color{#6700EE}{3}} = \color{#08ae08}{1\text{,01001}}_2 \rightarrow \color{#08ae08}{01001_2}\)
  6. Bestimmung des Exponent: \( \color{#d91b29}{\text{Bias}} + \color{#6700EE}{\text{Sprünge}} = \color{#d91b29}{127_{10}} + \color{#6700EE}{3} = \color{#ff8e00}{130_{10}} \)
    \( \color{#ff8e00}{130_{10}} \rightarrow \color{#ff8e00}{10000010_2} \)
  7. Alles zusammenschreiben: Vorzeichen + Exponent + Mantisse = \( \color{#4493f8}{0} \ \color{#ff8e00}{10000010} \ \color{#08ae08}{01001}000000000000000000 \)