how to separate hexadecimal

Paul Rubin http
Wed Feb 2 03:23:49 EST 2005


jrlen balane <nbbalane at gmail.com> 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 what you want.

If you want the hex form of the two's complement, just say

   hex(-(hi+lo) & 0xff)

assuming you want one byte, or

   hex(-(hi+lo) & 0xffff)

for two bytes.



More information about the Python-list mailing list