scipiguy

Logical Expressions and Python - Denary to Binary Converter

Oct 28th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. print("This little bit of code will convert adenary number into binary.\n")
  2.  
  3. denarynumber = int(input("Please enter your denary number: "))
  4. string = ""
  5.  
  6. while denarynumber > 0:
  7.     string = str(denarynumber % 2)+ string #Adds a 0 if the number divides exactly by 2
  8.     denarynumber = denarynumber // 2
  9.  
  10. print(string)
Advertisement
Add Comment
Please, Sign In to add comment