+ 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 Answers
+ 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