Non-POSIX parity (mark/space) with Python-Serial on Linux.
Grant Edwards
invalid at invalid.invalid
Mon Nov 21 18:08:12 EST 2011
On 2011-11-21, David Riley <fraveydank at gmail.com> wrote:
> 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).
Like the old joke:
There are 10 kinds of people in the world: those who understand
binary numbers, and those who don't.
--
Grant Edwards grant.b.edwards Yow! ... I don't like FRANK
at SINATRA or his CHILDREN.
gmail.com
More information about the Python-list
mailing list