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?

askedAug 27, 2015 at 4:53
uMinded's user avatar
3
  • Try:"{0:b}".format(strNUMBER)CommentedAug 27, 2015 at 4:56
  • 1
    You might be interested in the built-inbin() function.CommentedAug 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?CommentedAug 27, 2015 at 5:11

1 Answer1

1

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

a = '{0:016b}'.format(int(strNUMBER))
answeredAug 27, 2015 at 5:30
Abhi's user avatar
Sign up to request clarification or add additional context in comments.

1 Comment

@uMinded your Welcome :)

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.