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

D

David Riley

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
 
G

Grant Edwards

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.
 
G

Grant Edwards

Like the old joke:

There are 10 kinds of people in the world: those who understand
binary numbers, and those who don't.

OK, it's not _much_ of a joke, but I don't get to use it very often,
so I couldn't let it go (for one thing, it only works in "print").
 
C

Chris Angelico

OK, it's not _much_ of a joke, but I don't get to use it very often,
so I couldn't let it go (for one thing, it only works in "print").

On a scale of 1 to 10, what is the probability that this is in binary?

There's plenty of great binary jokes going around.

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top