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
Doppelte Genauigkeit (Double Precision) – 64-Bit
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} \)
- Vorzeichen bestimmen: \(0\)
- 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 \) - Nachkommazahl umrechnen:
\(0\text{,25} \cdot 2 = 0\text{,5 (0)} \ \ \ \ \big\downarrow \)
\(0\text{,5} \cdot 2 = 1\text{ (1)} \)
\( \rightarrow 01_2 \) - VK und NK kombinieren: \( 1010_2 \text{ und } 01_2 = 1010\text{,01}_2 \)
- Zahl “normalisieren”: \(1010\text{,01}_2 \cdot 10^{\color{#6700EE}{3}} = \color{#08ae08}{1\text{,01001}}_2 \rightarrow \color{#08ae08}{01001_2}\)
- 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} \) - Alles zusammenschreiben: Vorzeichen + Exponent + Mantisse = \( \color{#4493f8}{0} \ \color{#ff8e00}{10000010} \ \color{#08ae08}{01001}000000000000000000 \)