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?
asked Aug 27, 2015 at 4:53
uMinded
6051 gold badge11 silver badges22 bronze badges
1 Answer 1
you can use the below method to get a 16 digit binary of an integer
a = '{0:016b}'.format(int(strNUMBER))
answered Aug 27, 2015 at 5:30
Abhi
5521 gold badge10 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Abhi
@uMinded your Welcome :)
Explore related questions
See similar questions with these tags.
lang-py
"{0:b}".format(strNUMBER)bin()function.