+ 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

23rd Mar 2019, 4:05 PM
성동헌
성동헌 - avatar
4 Réponses
+ 8
result = str(bin(remainder)) + str(bin(decimal)) ?
24th Mar 2019, 1:47 PM
Николай Шаповаленко
Николай Шаповаленко - avatar
+ 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
23rd Mar 2019, 6:17 PM
Clueless Coder
Clueless Coder - avatar
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....'
23rd Mar 2019, 11:16 PM
성동헌
성동헌 - avatar
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))
23rd Mar 2019, 11:22 PM
성동헌
성동헌 - avatar