[Tutor] Extracting bits from an array

Oscar Benjamin oscar.j.benjamin at gmail.com
Sat Apr 30 05:09:18 EDT 2016


On 30 Apr 2016 08:14, "Peter Otten" <__peter__ at web.de> wrote:
>
> Peter Otten wrote:
>
> > Anish Kumar wrote:
> >
> >> Right shifting is well defined in Python?
> >
> > Yes. What might surprise someone used to fixed-size integers:
> >
> >>>> -1 >> 1
> > -1
> >
> > Any negative int will eventually end as -1:
> >
> >>>> -1234 >> 10
> > -2
> >>>> -1234 >> 11
> > -1
>
> I just checked and C works the same. Sorry for spreading misinformation.

Bitwise operations on signed types are undefined (hence best avoided) in C.

--
Oscar


More information about the Tutor mailing list