dst_unavailable
dst_unavailable

Reputation: 19

Python long to formatted string

I am using python to convert a long to little endian:

import struct

test = "0xbfffef40";
print(struct.pack('<L', long(test, 16)))

which displays as

@???

But I am having issues working out a nice way to print it in the form:

\x40\xef\xff\xbf

As a string to the terminal (just for logging).

Upvotes: 1

Views: 87

Answers (1)

Prasun Chakraborty
Prasun Chakraborty

Reputation: 547

You can try this code with little improvements

import struct
test = "0xbfffef40"
print(struct.pack('<L',int(test, base=16)))

Upvotes: 1

Related Questions