Initial commit
This commit is contained in:
commit
a1ddfdb7c0
14 changed files with 599 additions and 0 deletions
25
exercise_1/task3.py
Normal file
25
exercise_1/task3.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
def divtwo(x):
|
||||
if (x >= 0):
|
||||
a = 0
|
||||
z = 0
|
||||
# Wie oft passt die 2 in x
|
||||
while (a <= x):
|
||||
a = (a + 2)
|
||||
z = (z + 1)
|
||||
z = (z - 1)
|
||||
else:
|
||||
z = 0
|
||||
return z
|
||||
|
||||
def bin(n):
|
||||
if (n == 0):
|
||||
print(0)
|
||||
if (n > 0):
|
||||
a = n
|
||||
# Das Verfahren zur Bestimmung der Binärdarstellung aus der Vorlesung
|
||||
while (a > 0):
|
||||
q = divtwo(a) # Quotient
|
||||
r = (a - (q + q)) # Rest berechnen
|
||||
a = q # Nächste Zeile im Verfahren
|
||||
print(r)
|
||||
return 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue