On Nov 21, 2011, at 2:29 PM, Matthew Lenz wrote:

> Another thing I noticed is that the & and | appear to give the same result as 
> adding or subtracting 128 from the ordinal value.  I'm assuming that isn't 
> coincidence. :)

It's not, though the difference is important.  They're binary ANDs (&) and ORs 
(|), so (0x0F | 0x80) = 0x8F, but (0x8F | 0x80) = 0x8F as well, whereas (0x8F + 
0x80) = 0x10F.  For manipulating bit values (which is what you're doing, you 
should almost never be adding or subtracting, but rather ANDing and ORing (or 
XORing, but not nearly as often).

Just in case you're not familiar, 0x is the prefix for a hexadecimal number. 
0x80 = 128, which is binary 10000000 (i.e. the high bit in a byte).


- Dave
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to