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>
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
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
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.
> >
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:
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
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"