Dave Angel ieee.org> writes:
> Once you have an *array* of integers, you have much more than 32 bits to
> work with. For example, with an array of size 10, you now have 320 bits
> to work with. He's just pointing out that it's a little bit awkward to
> address a group of bits that are not al
Robert Berman wrote:
Emille,
I do think he meant bit 20 to 32 rather than 20 to 40. Unless, of
course, he's dealing with a 64 bit word.
You posted out of order (top--osted). So I am forced to put my response
elsewhere.
I am delighted with all the help I have received on this topic and I a
Emille,
I do think he meant bit 20 to 32 rather than 20 to 40. Unless, of
course, he's dealing with a 64 bit word.
I am delighted with all the help I have received on this topic and I am
gleefully learning anding and oring, but not too much on the EOR side.
Thanks again for all the assistance.
On 12/2/2009 4:10 PM GilJohnson said...
Using an array of 32 bit integers, you have to go to some
trouble to slice out, say, bits 20 to 40.
I think I agree -- if in fact it's not impossible. Tell me that's a
typo or take a moment to explain what I'm misunderstanding...
Emile
"Robert Berman" wrote
I am trying to represent a number as a list of bits: for example the bit
representation of the integer 8.
Numbers are already represented as arrays of bits, thats how
they are stored.
I am almost certain there is a relatively easy way to convert an integer
that can b
As`Kent Johnson pointed out, you don't need to convert anything to strings, etc.
An integer _is_ a bit array, and individual bits can be tested using the bitwise
operators. For your example, if A is an integer you can test bit 8 with:
if A & (1 << 8): dosomething
There is a simple example on the Py
On Mi, 2009-12-02 at 13:08 -0500, Robert Berman wrote:
> Hi,
>
> I am trying to represent a number as a list of bits: for example the
> bit representation of the integer 8. I did find a number of articles
> pertaining to a module called bitarray but I was unable to
> download/install that package.
On Wed, Dec 2, 2009 at 1:08 PM, Robert Berman wrote:
> Hi,
>
> I am trying to represent a number as a list of bits: for example the bit
> representation of the integer 8. I did find a number of articles pertaining
> to a module called bitarray but I was unable to download/install that
> package. I
My approach has been to store it as an array and then build the integer as
needed. This code requires Python 2.5 or later.
def bits2int(l):
return sum([2**i if j else 0 for i,j in enumerate(l)])
To convert the other way:
def int2bits(m, n):
return [int(bool(m&(1<>= inc
return i
flo
Wayne,
Thank you very much.
Robert
On Wed, 2009-12-02 at 12:48 -0600, Wayne Werner wrote:
> On Wed, Dec 2, 2009 at 12:08 PM, Robert Berman
> wrote:
>
> Hi,
>
> I am trying to represent a number as a list of bits: for
> example the bit representation of the inte
On Wed, Dec 2, 2009 at 12:08 PM, Robert Berman wrote:
> Hi,
>
> I am trying to represent a number as a list of bits: for example the bit
> representation of the integer 8. I did find a number of articles pertaining
> to a module called bitarray but I was unable to download/install that
> package
Hi,
I am trying to represent a number as a list of bits: for example the bit
representation of the integer 8. I did find a number of articles
pertaining to a module called bitarray but I was unable to
download/install that package. I am using Linux on Ubuntu 9.10; Python
2.6.2.
I am almost certa
12 matches
Mail list logo