FAQ
Hi,

Can anobody point to or provide a simple example of bit manipulation using
plain python?

Thomas

Search Discussions

  • Hans Nowak at Aug 16, 2001 at 10:34 am

    ===== Original Message From "Thomas Weholt" <thomas at gatsoft.no> =====
    Hi,

    Can anobody point to or provide a simple example of bit manipulation using
    plain python?
    Not sure what you want here... You can use the & ^ | >> << operators, like in
    C. A trivial example:
    a = 2001
    a & 1973
    1937
    a | 1973
    2037
    a ^ 1973
    100
    a >> 1
    1000
    a << 1
    4002

    If you meant something more sophisticated, like high-level functions to set
    the Nth bit of a number, or working with binary numbers, then I might have
    something in my snippet collection. I can look it up for you if you want.

    HTH,

    --Hans Nowak
  • Alex Martelli at Aug 16, 2001 at 4:05 pm
    "Thomas Weholt" <thomas at gatsoft.no> wrote in message
    news:ODLe7.864$y9k.170724864 at news.telia.no...
    Hi,

    Can anobody point to or provide a simple example of bit manipulation using
    plain python?
    You mean "bit manipulation" as in:
    x=0xdeadbeef
    low=0xFFFF
    "%x"%(x&low)
    'beef'
    "%x"%(x>>16&low)
    'dead'
    >>>

    or what?


    Alex

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 16, '01 at 8:38a
activeAug 16, '01 at 4:05p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase