Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def decToBin(input):
- global bin
- bin = ""
- while input >= 1:
- bdigit = str(input % 2) #binary digit
- input = input/2 #divides input by 2
- bin = bin + bdigit # concatenates 1 or 0 to full binary digit
- return int(bin[::-1]) #reverses string
- def binToDec(input):
- input = str(input)
- input = input[::-1]
- z = 1 #number to multiply by
- for i in input:
- choice = ""
- while choice != "q":
- if choice == "dec":
- a = input("Decimal number: ")
- print decToBin(a)
- if choice == "bin":
- a = input("Binary digit: ")
- print binToDec(a)
- if choice == "q":
- break
- choice = raw_input("dec, bin, or q: ")
Add Comment
Please, Sign In to add comment