Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

Python : convert a hex string

//Duplicated question are deleted.

I would like to convert a hex string like this:

b'x0fx00x00x00NR09G05164x00' //This is what I've received from socket

To something like:

0f0000004e52303947303531363400

How can I achieve this using Python?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use binascii.hexlify():

In [25]: strs=b'x0fx00x00x00NR09G05164x00'

In [26]: import binascii

In [27]: binascii.hexlify(strs)
Out[27]: b'0f0000004e52303947303531363400'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...