Bits from Numbers.

Discussion in 'Python' started by sdd, Jan 8, 2004.

  1. sdd

    sdd Guest

    I am whacking away at some code to view numbers as bit sequences.
    While this is not complete, I'd appreciate some feedback from anyone
    who is interested in looking at it:
    http://members.dsl-only.net/~daniels/bits.html

    As the page describes, bit extract of more than an int's worth of bits
    from a long at one go does not yet work.


    The basic idea is that the (non-complex) python numbers can be
    viewed as an infinite binary bit stream:

    ...........000101.11000..... is 5.75

    There are functions to get the least and most significant bit
    numbers, examine a particular bit, and extract a consecutive
    chunk of bits.

    At the bottom of the page are links to source archives and windows
    installers for 2.2 and 2.3.

    For now, consider this a pre-alpha. I am soliciting comments
    on both the definitions and names of the functions provided.

    However, I'd like to point out now that negative integers have
    an infinite number of ones _and_ zeros in their expansion above,
    so popcount as traditionally defined for negative integers is
    unworkable.

    -Scott David Daniels
    sdd, Jan 8, 2004
    #1
    1. Advertising

  2. |Thus Spake sdd On the now historical date of Wed, 07 Jan 2004 16:36:43
    -0800|

    > I am whacking away at some code to view numbers as bit sequences. While
    > this is not complete, I'd appreciate some feedback from anyone who is
    > interested in looking at it:


    I must say that your module seems to be well thought-out and useful.
    I am particularly glad to see the list of identities on the bottom.
    Kudos.

    Fair warning, I just read the web-page. I haven't yet tried using the
    module.

    You might try creating a couple of generators so that someone could
    iterate through through bit-sequences. I envision four generators:

    The first set of two would return a stream of bit-positions from either
    ms to ls or ls to ms directions.

    The second set would return each bit in a range of bit-positions either
    from ms to ls or ls to ms.

    I used a similar set of python functions while studying compression and
    error correction in data streams. I created some generators that allowed
    me to step through files bit-by-bit. If you think this might be a useful
    addition, I'll dig up the code for you and we can work on integrating it
    into your module.

    HTH

    Sam Walters.


    --
    Never forget the halloween documents.
    http://www.opensource.org/halloween/
    """ Where will Microsoft try to drag you today?
    Do you really want to go there?"""
    Samuel Walters, Jan 8, 2004
    #2
    1. Advertising

  3. sdd

    Miki Tebeka Guest

    Hello Scott,

    > I am whacking away at some code to view numbers as bit sequences.
    > While this is not complete, I'd appreciate some feedback from anyone
    > who is interested in looking at it:
    > http://members.dsl-only.net/~daniels/bits.html

    Looks great.

    Several things:
    1. I think a new object "bitarray" which will be a subclass of "list" will be
    more "natural". Then you'll get:
    bitcount(n) -> n.count(1)
    bit(n, x) -> n[x]
    extract(x, lo, hi) -> n[lo:high]
    ...
    2. There is no function to set a range of bits n = setbits(n, start, end, value)
    3. I'd prototype it first in Python and after the interface has matured move it
    to C. This way you'll be able to make changes faster. (This is the way the
    Python library works - see sets, itertools, heapq ...)

    HTH.
    Miki.
    Miki Tebeka, Jan 8, 2004
    #3
  4. On Wed, 07 Jan 2004 16:36:43 -0800, rumours say that sdd
    <> might have written:

    >I am whacking away at some code to view numbers as bit sequences.
    >While this is not complete, I'd appreciate some feedback from anyone
    >who is interested in looking at it:
    > http://members.dsl-only.net/~daniels/bits.html


    Is it similar to BitDecoder which you can find at the Python Package
    Index?

    http://www.python.org/pypi?:action=display&name=BitDecoder&version=0.5.1

    If yes, perhaps you should contact its author and then co-operate on it.
    --
    TZOTZIOY, I speak England very best,
    Ils sont fous ces Redmontains! --Harddix
    Christos TZOTZIOY Georgiou, Jan 8, 2004
    #4
  5. On Wed, 07 Jan 2004 16:36:43 -0800, sdd <> wrote:

    >I am whacking away at some code to view numbers as bit sequences.
    >While this is not complete, I'd appreciate some feedback from anyone
    >who is interested in looking at it:
    > http://members.dsl-only.net/~daniels/bits.html
    >
    >As the page describes, bit extract of more than an int's worth of bits
    >from a long at one go does not yet work.
    >
    >
    >The basic idea is that the (non-complex) python numbers can be
    >viewed as an infinite binary bit stream:
    >
    > ...........000101.11000..... is 5.75
    >
    >There are functions to get the least and most significant bit
    >numbers, examine a particular bit, and extract a consecutive
    >chunk of bits.
    >
    >At the bottom of the page are links to source archives and windows
    >installers for 2.2 and 2.3.
    >
    >For now, consider this a pre-alpha. I am soliciting comments
    >on both the definitions and names of the functions provided.
    >
    >However, I'd like to point out now that negative integers have
    >an infinite number of ones _and_ zeros in their expansion above,
    >so popcount as traditionally defined for negative integers is
    >unworkable.


    No time to look now, but maybe

    http://mail.python.org/pipermail/python-list/2003-December/199683.html

    will give you something useful? BTW, it proposes a literal string format that takes
    care of the infinitely repeating sign bit problem (i.e., you don't repeat it, except
    for representing -1 as '11b' for symmetry with '01b' for +1) but you always have a one
    or zero leading bit that you can repeat as needed to make whatever width.

    Regards,
    Bengt Richter
    Bengt Richter, Jan 9, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GGG
    Replies:
    10
    Views:
    12,552
    Donar
    Jul 6, 2006
  2. sarmin kho
    Replies:
    2
    Views:
    825
    A. Lloyd Flanagan
    Jun 15, 2004
  3. Miki Tebeka
    Replies:
    1
    Views:
    443
    Marcin 'Qrczak' Kowalczyk
    Jun 14, 2004
  4. sergey

    "casting" bits to bits?

    sergey, Nov 8, 2006, in forum: VHDL
    Replies:
    1
    Views:
    705
    sergey
    Nov 8, 2006
  5. Tomás

    Value Bits Vs Object Bits

    Tomás, Jun 2, 2006, in forum: C Programming
    Replies:
    13
    Views:
    547
    Hallvard B Furuseth
    Jul 1, 2006
Loading...

Share This Page