~ 1 = -2 ???

Les Schaffer godzilla at netmeg.net
Fri Nov 5 05:38:37 CET 1999


william tanksley added this marble to my collection:

> The marble about 32-bit twos' complement signed integers.  They're
> not four-bit, BTW.

its not even midnite and i am already brain-dead, yeeesh.

i was doing ops on 4 bit numbers, so i fooled myself.

i should have said:

0000 0001 --> 1111 1110 

and to keep only the 4 lower bits...

1111 1110 & 0000 1111 --> 0000 1110 

which equals 14, not 13 (sheesh... nobody is ever gonna listen to me
again)

so for my code, i will do

def not4bit(x):
      return ~x & 15

>>> not4bit(1)
14

ahh, that feels better....

goodnite world.

les schaffer




More information about the Python-list mailing list