[Tutor] how to separate hexadecimal

Ewald Ertl ewald.ertl at hartter.com
Wed Feb 2 11:19:45 CET 2005


Hi!

Using binary operations: 

>>> a='0x87BE'
>>> str(hex(int(a,16) & 0xFF))
'0xbe'
>>> str(hex((int(a,16) & 0xFF00) / 0xFF))
'0x87'
>>> 

HTH Ewald 

on Wed, 2 Feb 2005 15:10:36 +0800  jrlen balane <nbbalane at gmail.com> wrote :
---------------------------------------------------------------------------------------------

jrlen balane > i have a 4 digit hex number (2 bytes) and i want to separate it into 2
jrlen balane > digit hex (1 byte each) meaning i want to get the upper byte and the
jrlen balane > lower byte since i am going to add this two.
jrlen balane > how am i going to do this?
jrlen balane > should i treat it just like a normal string?
jrlen balane > please help, thanks.
jrlen balane > 
jrlen balane > ex. hexa = '0x87BE"  # what i want to do is:
jrlen balane >       a = 0x87, b = 0xBE    # so that i could do this:
jrlen balane >       c = a + b            #which should be equal to 0x145
jrlen balane > _______________________________________________
jrlen balane > Tutor maillist  -  Tutor at python.org
jrlen balane > http://mail.python.org/mailman/listinfo/tutor
jrlen balane > 


------------------- end ----------------------



More information about the Tutor mailing list