On 30 Apr 2016 08:14, "Peter Otten" <__pete...@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 e
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 work
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
___
Tutor maillist - Tut
On 29/04/16 20:47, Anish Kumar wrote:
>> Is the number of bits fixed to four? If so you can shift the bits to the
>> right:
>>
> y = [v>>2 for v in x]
>
> Right shifting is well defined in Python?
Yes, Python has good support for all the common bitwise
operations, including the shift right/
> On Apr 29, 2016, at 1:15 PM, Colin Ross wrote:
>
> Hello,
>
> I have an array that takes on the following form:
>
> x = [1000,1001,1011,]
>
> The array elements are meant to be binary representation of integers.
>
> Goal: Access array elements and extract the first two bits.
>
> e.g.
>
>> Hello,
>>
>> I have an array that takes on the following form:
>>
>> x = [1000,1001,1011,]
>
> But these are actually integers in decimal representation. You could treat
> them as binary, but I recommend that you use integers in binary
> representation to avoid confusion:
>
x
Colin Ross wrote:
> Hello,
>
> I have an array that takes on the following form:
>
> x = [1000,1001,1011,]
But these are actually integers in decimal representation. You could treat
them as binary, but I recommend that you use integers in binary
representation to avoid confusion:
>>> x =
Thank you Michael, this is exactly what I was looking for! Clears things up
on multiple fronts : )
On Fri, Apr 29, 2016 at 2:29 PM, Michael Selik
wrote:
>
>
> > On Apr 29, 2016, at 1:15 PM, Colin Ross
> wrote:
> >
> > Hello,
> >
> > I have an array that takes on the following form:
> >
> > x =