0

How to convert binary to text in python

Python

24th Nov 2020, 7:24 PM
victor bamidele
victor bamidele - avatar
2 odpowiedzi
+ 4
victor bamidele , a binary number will mostly be shown in string format, as leading zeros's can not be represented in int format. To convert int representation to string you can use str() function. to fill leading zeros you can use string method rjust(<binary string>, <fill character>). Please do a try, if you feel a problem come back. bin = 100110 print(str(bin).rjust(8,"0") If this is not the answer you expect, please make a sample of input, and a sample how the output should look like.
24th Nov 2020, 7:51 PM
Lothar
Lothar - avatar