+ 1
How can I change from real # to binary #?
I want to change from real number to binary number to use python coding. but it is very hard to me... help me
4 Answers
+ 8
result = str(bin(remainder)) + str(bin(decimal))
?
+ 4
It is a built in function in Python. There are
hex(4) returns hex value of 4
bin(7) returns binary value of 7
oct(5) returns oct value of 5
Here is an example:
https://code.sololearn.com/cweokwkyVFdv/?ref=app
0
oh, it's nice. but it is not what I want.
example, i put 3.3, then output is '101.010101....' and -4.4 is '-100.110011....'
0
This is my coding but it is not complete.
decimal = int(input('num:',))
result = ''
while (decimal > 0) :
remainder = decimal % 2
decimal = decimal // 2
result = str(remainder) + result
print((result))