Non-POSIX parity (mark/space) with Python-Serial on Linux.

David Riley fraveydank at gmail.com
Mon Nov 21 15:42:23 EST 2011


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


More information about the Python-list mailing list