bitwise not - not what I expected

Elaine Jackson elainejackson7355 at home.com
Sun Aug 17 00:58:37 EDT 2003


Is there a function that takes a number with binary numeral a1...an to the
number with binary numeral b1...bn, where each bi is 1 if ai is 0, and vice
versa? (For example, the function's value at 18 [binary 10010] would be 13
[binary 01101].) I thought this was what the tilde operator (~) did, but when I
went to try it I found out that wasn't the case. I discovered by experiment (and
verified by looking at the documentation) that the tilde operator takes n
to -(n+1). I can't imagine what that has to do with binary numerals. Can anyone
shed some light on that? (In case you're curious, I'm writing a script that will
play Nim, just as a way of familiarizing myself with bitwise operators. Good
thing, too: I thought I understood them, but apparently I don't.)

Muchas gracias for any and all helps and hints.

Peace,
EJ






More information about the Python-list mailing list