0

I'm sure this question has been asked before, but I can't find and answer.

How can I convert an integer to raw data?

Here's an example of what I'd like to do, convert 0x41424344 to 'ABCD'?

I know chr(0x41) = 'A', but what's the python way of converting an int to a full raw data buffer?

Thanks in advance.

0

1 Answer 1

2

In Python 3:

>>> (0x41424344).to_bytes(4, 'big')
b'ABCD'

In Python 2.x - you could use struct:

>>> struct.pack('>i', 0x41424344)
'ABCD'
Sign up to request clarification or add additional context in comments.

Comments

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.