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

Categories

//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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use binascii.hexlify():

In [25]: strs=b'x0fx00x00x00NR09G05164x00'

In [26]: import binascii

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...