manipulating bits in python

Jim Richardson warlock at eskimo.com
Sun Oct 1 04:18:41 EDT 2000


On Sun, 01 Oct 2000 04:40:08 GMT, 
 Greg Jorgensen, in the persona of <gregj at pobox.com>,
 brought forth the following words...:

>Python has a full set of bitwise operators, which can be applied (only) to
>integers and long integers:
>
>x << y    left shift x by y bits
>x >> y    right shift
>x & y    bitwise and
>x | y    bitwise or
>x ^ y    bitwise xor
>~x    bitwise negation
>
>print "%x" % a    # print a as hex integer
>
>I recommend the excellent book "Python Essential Reference" by David
>Beazley.


Damn! I _have_ that book, but I checked the lib ref in the docs and didn't see
how to catch the bits...

>
>"Jim Richardson" <warlock at eskimo.com> wrote in message
>news:slrn8tckiq.h5.warlock at gargoyle.myth...
>> I have a ??? re: manipulating bits in python. I have a need to do quick
>and
>> simple bit twiddling, shiftright, invert etc. THe operator module has s
>shiftR
>> but how can I catch the bit that falls off without a lot of grotty_code?
>>  Also, I can't seem to figure a "invert" number, something that would take
>> for example, 0x01 and return 0xFE, I can do this fairly simply, but am
>confused
>> at not finding a simple call for it. Am I missing something? thanks all
>>
>> --
>> Jim Richardson
>> Anarchist, pagan and proud of it
>> WWW.eskimo.com/~warlock
>> Linux, because life's too short for a buggy OS.
>>
>
>


-- 
Jim Richardson
	Anarchist, pagan and proud of it
WWW.eskimo.com/~warlock
	Linux, because life's too short for a buggy OS.




More information about the Python-list mailing list