hex notation funtion

T

tertius

Hi,

Is there a builtin function that will enable me to display the hex
notation of a given binary string? (example below)

many thanks
Tertius



0000(0000) 02 11 00 00 46 5A 1A 82 02 11 00 39 36 39 33 39
.....FZ.....96939

0016(0010) 36 39 33 00 0A 30 33 37 34 34 39 35 38 25 DD 01
693..03744958%..
 
I

Irmen de Jong

tertius said:
Hi,

Is there a builtin function that will enable me to display the hex
notation of a given binary string? (example below)

Does this help:
'\xde\xad\xbe\xef'

?

--Irmen
 
P

Philippe C. Martin

Would that do it?

for i in my_byte_string:
.... = atoi(binascii.hexlify(i),16)

Regards,

Philippe
 
G

Grant Edwards

Is there a builtin function that will enable me to display the hex
notation of a given binary string? (example below)

' '.join('%02x' % ord(b) for b in s)
 
P

Peter Hansen

Grant said:
' '.join('%02x' % ord(b) for b in s)


Oops. Should be:

' '.join(['%02x' % ord(b) for b in s])

The first works fine under Python 2.4, actually... you
need the list comprehension only on previous versions.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top