~ bit-wise unary operator

Ladislav Andel ladaan at iptel.org
Thu Sep 27 02:46:56 EDT 2007


Wow, so many answers :). Thank you, guys :).

Lada

Michal Bozon wrote:
> cau,
> maybe int is represented internally as a signed integer
>
> you can use numpy types:
>
>   
>>>> import numpy
>>>> ~ numpy.uint16(7978)
>>>>         
> 57557
>
>  -m.
>
>
> On Thu, 27 Sep 2007 00:14:49 +0200, Ladislav Andel 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.
>>
>> which is also in binary
>> 0001111100101010
>> and inverted
>> 1110000011010101
>>
>> Is here any other operator or do I have to write it on my own?
>>
>> Thank you,
>> Lada
>>     
>
>   




More information about the Python-list mailing list