0

Given a 8-bytes long signed value, like 3576757170468630901, I would like to convert it to ASCII binarized hexadecimal:

For example:

>> hex(3576757170468630901).encode('ascii')
b'0x31a331b2319d3175'

What I am looking for is the following format:

b'\x31\xa3\x31\xb2\x31\x9d\x31\x75'

I am not sure how can I generate it? Should I break each block and convert it myself?

Coderji
  • 7,615
  • 5
  • 35
  • 48

1 Answers1

3

In python 3 there is now to_bytes() which may help here:

v = 3576757170468630901
print(hex(v))
print(v.to_bytes(8, 'big'))

Output:

0x31a331b2319d3175
b'1\xa31\xb21\x9d1u'
quamrana
  • 33,740
  • 12
  • 54
  • 68