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_hof [2024-05-05 08:35] – hof | gf_informatik:zahlensysteme_hof [2024-05-06 05:26] (aktuell) – hof | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
# Zahlensysteme | # Zahlensysteme | ||
+ | ## Umwandlung Dezimal - Binär | ||
+ | <code python binary_conversion.py> | ||
+ | def bin_to_dec(b): | ||
+ | """ | ||
+ | result = 0 | ||
+ | for digit in b: | ||
+ | result = result * 2 | ||
+ | if digit == ' | ||
+ | result = result + 1 | ||
+ | return result | ||
+ | |||
+ | def dec_to_bin(number): | ||
+ | """ | ||
+ | result = '' | ||
+ | while number > 0: | ||
+ | digit = number % 2 | ||
+ | number = number // 2 | ||
+ | result = result + str(digit) | ||
+ | return result | ||
+ | </ | ||
+ | ## Arithmetik | ||
<code python binary_arithmetics.py> | <code python binary_arithmetics.py> | ||
- | # " | ||
def gegenzahl(b, | def gegenzahl(b, | ||
+ | """ | ||
# 1. gewünschte Anzahl bits | # 1. gewünschte Anzahl bits | ||
while len(b) < stellen: | while len(b) < stellen: | ||
Zeile 18: | Zeile 39: | ||
# 3. plus 1 | # 3. plus 1 | ||
- | return addition(result, | + | return addition(result, |
def addition(one, | def addition(one, | ||
+ | """ | ||
# sicherstellen, | # sicherstellen, | ||
while len(one) < stellen: | while len(one) < stellen: | ||
Zeile 53: | Zeile 75: | ||
# Returns one - two | # Returns one - two | ||
def subtraktion(one, | def subtraktion(one, | ||
+ | """ | ||
stellen = len(one) | stellen = len(one) | ||
# gegenzahl von two | # gegenzahl von two |