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?
- Try:
"{0:b}".format(strNUMBER)Nir Alfasi– Nir Alfasi2015-08-27 04:56:20 +00:00CommentedAug 27, 2015 at 4:56 - 1You might be interested in the built-in
bin()function.PM 2Ring– PM 2Ring2015-08-27 04:56:53 +00:00CommentedAug 27, 2015 at 4:56 - @uMinded , do you mean you want to write to file as raw binary? or do you want to write to file as 16 ascii numbers?Anand S Kumar– Anand S Kumar2015-08-27 05:11:10 +00:00CommentedAug 27, 2015 at 5:11