~ bit-wise unary operator

Grant Edwards grante at visi.com
Wed Sep 26 19:15:17 EDT 2007


On 2007-09-26, Ladislav Andel <ladaan at iptel.org> wrote:
> Hello,
> why ~ bit-wise unary operator returns -(x+1) and not bit inversion of 
> the given integer?
>
> example:
> a = 7978
> a = ~a
> python returns -7979
>
> but I need to get back 57557 as in C language.

It's not what C language returns, but if you want 57557, you
can get it like this:

>>> (~7978) & 0xffff
57557

-- 
Grant Edwards                   grante             Yow! Do you think the
                                  at               "Monkees" should get gas on
                               visi.com            odd or even days?



More information about the Python-list mailing list