Re: how to separate hexadecimal

2005-02-02 Thread Nick Coghlan
Nick Coghlan wrote: When not working at the hardware level, just go with the definition: Py> def complement(val, limit=256): ... if val >= limit or val < 0: ... raise ValueError("Value out of range for complemented format") ... if val == 0: ... return 0 ... return limit - val ... Py>

Re: how to separate hexadecimal

2005-02-02 Thread Nick Coghlan
Paul Rubin wrote: jrlen balane <[EMAIL PROTECTED]> writes: would i be able to perform bitwise operation with the result? say, i want to get the two's complement of the result, is this correct: twos_complement = (~ hex(hi + lo)) + 1 You can do bit operations, but hex(n) is the hex string for n, whi

Re: how to separate hexadecimal

2005-02-02 Thread Paul Rubin
jrlen balane <[EMAIL PROTECTED]> writes: > would i be able to perform bitwise operation with the result? > say, i want to get the two's complement of the result, is this correct: > > twos_complement = (~ hex(hi + lo)) + 1 You can do bit operations, but hex(n) is the hex string for n, which is not

Re: how to separate hexadecimal

2005-02-02 Thread jrlen balane
On Wed, 02 Feb 2005 17:36:04 +1000, Nick Coghlan <[EMAIL PROTECTED]> wrote: > jrlen balane wrote: > > i have a 4 digit hex number (2 bytes) and i want to separate it into 2 > > digit hex (1 byte each) meaning i want to get the upper byte and the > > lower byte since i am going to add this two. > >

Re: how to separate hexadecimal

2005-02-01 Thread Paul Rubin
jrlen balane <[EMAIL PROTECTED]> writes: > ex. hexa = '0x87BE" # what i want to do is: > a = 0x87, b = 0xBE# so that i could do this: > c = a + b#which should be equal to 0x145 Assuming you really want hexa to begin with the characters '0x', the string slicing way is:

Re: how to separate hexadecimal

2005-02-01 Thread Nick Coghlan
jrlen balane wrote: i have a 4 digit hex number (2 bytes) and i want to separate it into 2 digit hex (1 byte each) meaning i want to get the upper byte and the lower byte since i am going to add this two. how am i going to do this? should i treat it just like a normal string? please help, thanks. e

how to separate hexadecimal

2005-02-01 Thread jrlen balane
i have a 4 digit hex number (2 bytes) and i want to separate it into 2 digit hex (1 byte each) meaning i want to get the upper byte and the lower byte since i am going to add this two. how am i going to do this? should i treat it just like a normal string? please help, thanks. ex. hexa = '0x87BE"