Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Denary to Binary Conversion
- # Variables: denary_value, binary_string
- print('This program will convert a denary (base 10) non-negative integer to a binary (base 2) number.')
- denary_value = int(input('Enter a non-negative integer (base 10): '))
- print ("denary value is ", denary_value)
- original_denary_value = denary_value
- binary_string ='' # initialize the binary_string to an empty string
- while (denary_value > 0):
- binary_string = str(denary_value%2) + binary_string # this is a concatenation of strings
- print(binary_string) # intermeidate step to check calculations (can delete)
- denary_value = denary_value//2
- print(denary_value) # intermeidate step to check calculations (can delete)
- print('The binary representation of ', original_denary_value, ' is: ', binary_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement