~ 1 = -2 ???

Mikael Olofsson mikael at isy.liu.se
Fri Nov 5 04:10:32 EST 1999


On 05-Nov-99 Les Schaffer wrote:
 >  i am doing some bit operations, and dont understand the following:
 >  
 > >>> ~ 1
 >  -2
 >  
 >  huh???? i would have thought that bitwise invert of 1 would be
 >  
 >  0001 --> 1110 = 13 (base 10)
 >  
 >  what marble am i missing?

Hmmm, I always thought that 1110 binary would be 14 in base 10. Then it
makes sence, since 14 and -2 are equivalent mod 16 (4 bits).

/Mikael

-----------------------------------------------------------------------
E-Mail:  Mikael Olofsson <mikael at isy.liu.se>
WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date:    05-Nov-99
Time:    11:08:02

This message was sent by XF-Mail.
-----------------------------------------------------------------------




More information about the Python-list mailing list