0

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?

3
  • Try: "{0:b}".format(strNUMBER) Commented Aug 27, 2015 at 4:56
  • 1
    You might be interested in the built-in bin() function. Commented Aug 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? Commented Aug 27, 2015 at 5:11

1 Answer 1

1

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

a = '{0:016b}'.format(int(strNUMBER))
Sign up to request clarification or add additional context in comments.

1 Comment

@uMinded your Welcome :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.