Re: [Tutor] Extracting bits from an array

2016-04-30 Thread Oscar Benjamin
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

Re: [Tutor] Extracting bits from an array

2016-04-30 Thread Peter Otten
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

Re: [Tutor] Extracting bits from an array

2016-04-29 Thread Peter Otten
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

Re: [Tutor] Extracting bits from an array

2016-04-29 Thread Alan Gauld via Tutor
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/

Re: [Tutor] Extracting bits from an array

2016-04-29 Thread Michael Selik
> 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.

Re: [Tutor] Extracting bits from an array

2016-04-29 Thread Anish Kumar
> >> 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

Re: [Tutor] Extracting bits from an array

2016-04-29 Thread Peter Otten
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 =

Re: [Tutor] Extracting bits from an array

2016-04-29 Thread Colin Ross
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 =