Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!news-out.readnews.com!transit4.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: Non-POSIX parity (mark/space) with Python-Serial on Linux. Date: Mon, 21 Nov 2011 23:08:12 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 18 Message-ID: References: <27511132.925.1321884055247.JavaMail.geo-discussion-forums@yqnf38> <201111211225.54775.gheskett@wdtv.com> <2A18CB23-4EDC-46E9-A49D-DEDE28C7FBEF@gmail.com> <6568831.884.1321903764225.JavaMail.geo-discussion-forums@yqhd1> NNTP-Posting-Host: dsl.comtrol.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reader1.panix.com 1321916892 14400 64.122.56.22 (21 Nov 2011 23:08:12 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 21 Nov 2011 23:08:12 +0000 (UTC) User-Agent: slrn/pre0.9.9-102 (Linux) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16053 On 2011-11-21, David Riley 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