简体   繁体   中英

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).

You can try this code with little improvements

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM