Re: ~ bit-wise unary operator

2007-09-26 Thread Ladislav Andel
t; > -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 >> pyth

Re: ~ bit-wise unary operator

2007-09-26 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Hrvoje Niksic wrote: > If you want 16-bit unsigned arithmetic, use 2**16 + ~a, which yields > 57557. Or why not use "0x ^ a", which returns the same thing. -- http://mail.python.org/mailman/listinfo/python-list

Re: ~ bit-wise unary operator

2007-09-26 Thread Michal Bozon
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 i

Re: ~ bit-wise unary operator

2007-09-26 Thread Grant Edwards
On 2007-09-26, Ladislav Andel <[EMAIL PROTECTED]> 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

Re: ~ bit-wise unary operator

2007-09-26 Thread Hrvoje Niksic
Ladislav Andel <[EMAIL PROTECTED]> writes: > Hello, why ~ bit-wise unary operator returns -(x+1) and not bit > inversion of the given integer? On 2s-complement architectures, -(x+1) *is* bit inversion of the given integer. > example: > a = 7978 > a = ~a > python returns

Re: ~ bit-wise unary operator

2007-09-26 Thread Paul Hankin
On Sep 26, 11:14 pm, Ladislav Andel <[EMAIL PROTECTED]> 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

~ bit-wise unary operator

2007-09-26 Thread Ladislav Andel
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 000100101010 and inverted 111011010101 Is here any other operator or do