Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. # comment: convert a number from denary to binary
  2.  
  3. print('Give the integer positive number to be converted to binary')
  4. value = int(input ('What is number? '))
  5. div_value=value
  6. bin_string=''
  7. while (div_value!=0):
  8.         if (div_value%2):
  9.                 bin_string= '1'+bin_string
  10.         else:
  11.                 bin_string= '0'+bin_string
  12.         div_value=div_value//2
  13.    
  14. print ('The denary number is: ',value,' the binary string is: ', bin_string )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement