mirror of
https://github.com/Bobertkiller/Decimal-to-binary-number-converter.git
synced 2026-01-15 13:12:53 -03:00
Create converter.py
This commit is contained in:
23
converter.py
Normal file
23
converter.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#Decimal to binary number converter
|
||||
|
||||
decimal = int(input("Insert a decimal number: "))
|
||||
a = int(input("How many bytes do you desire? "))
|
||||
|
||||
cards = []
|
||||
t = []
|
||||
for i in range(a-1, -1,-1):
|
||||
cards.append(2**i)
|
||||
t.append(0)
|
||||
|
||||
r = decimal
|
||||
g = 0
|
||||
|
||||
while r !=0:
|
||||
if r >= cards[g]:
|
||||
r = r - cards[g]
|
||||
t[g] = cards[g]
|
||||
if t[g] != 0:
|
||||
t[g] = 1
|
||||
print(r)
|
||||
g = g + 1
|
||||
print("Yor decimal number converted to Binary is:", *t, sep ="")
|
||||
Reference in New Issue
Block a user