uMinded
uMinded

Reputation: 595

Python string to binary string

I need to convert a decimal read from a list in string form and output its binary equivalent to a text file.

I can convert the string to binary via:

line = format(int(strNUMBER), '016b')

but when I write it to a file it is in raw binary and not 16 ascii numbers as I want.

Is there a built in function flow to do this or will I need to walk the binary and fill a list with 1's and 0's manually?

Upvotes: 0

Views: 1775

Answers (1)

Abhi
Abhi

Reputation: 552

you can use the below method to get a 16 digit binary of an integer

a = '{0:016b}'.format(int(strNUMBER))

Upvotes: 1

Related Questions