Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. def decToBin(input):
  2. global bin
  3. bin = ""
  4. while input >= 1:
  5. bdigit = str(input % 2) #binary digit
  6. input = input/2 #divides input by 2
  7. bin = bin + bdigit # concatenates 1 or 0 to full binary digit
  8. return int(bin[::-1]) #reverses string
  9.  
  10. def binToDec(input):
  11. input = str(input)
  12. input = input[::-1]
  13. z = 1 #number to multiply by
  14. for i in input:
  15.  
  16.  
  17.  
  18. choice = ""
  19. while choice != "q":
  20. if choice == "dec":
  21. a = input("Decimal number: ")
  22. print decToBin(a)
  23. if choice == "bin":
  24. a = input("Binary digit: ")
  25. print binToDec(a)
  26. if choice == "q":
  27. break
  28. choice = raw_input("dec, bin, or q: ")
Add Comment
Please, Sign In to add comment