Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
| gf_informatik:zahlensysteme:binary_solutions [2026-04-01 17:34] – hof | gf_informatik:zahlensysteme:binary_solutions [2026-04-02 09:54] (aktuell) – [Umwandlung Dezimal-Binär] hof | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| ## Binärzahl-Operationen mit Python | ## Binärzahl-Operationen mit Python | ||
| < | < | ||
| - | |||
| ### Umwandlung Binär-Dezimal | ### Umwandlung Binär-Dezimal | ||
| Zeile 23: | Zeile 22: | ||
| 1. **Zwei separate Variablen**: | 1. **Zwei separate Variablen**: | ||
| 2. **Binärstring umkehren**, also aus `' | 2. **Binärstring umkehren**, also aus `' | ||
| - | | + | |
| <nodisp 1> | <nodisp 1> | ||
| Zeile 32: | Zeile 31: | ||
| """ | """ | ||
| d = 0 | d = 0 | ||
| + | exponent = len(b) - 1 | ||
| for digit in b: | for digit in b: | ||
| - | d = d*2 | ||
| if digit == ' | if digit == ' | ||
| - | d = d + 1 | + | d = d + 2**exponent |
| + | exponent = exponent - 1 | ||
| return d | return d | ||
| - | print(binary_to_decimal(" | + | print(binary_to_decimal(" |
| + | </ | ||
| ++++ | ++++ | ||
| </ | </ | ||
| - | |||
| ### Umwandlung Dezimal-Binär | ### Umwandlung Dezimal-Binär | ||
| Der {{gf_informatik: | Der {{gf_informatik: | ||
| - | < | + | < |
| ++++Lösung| | ++++Lösung| | ||
| < | < | ||