Set parity of a string

Peter Hansen peter at engcorp.com
Wed Jan 26 15:47:23 EST 2005


snacktime wrote:
> Correction on this, ETX is ok, it seems to be just STX with the data I am using.

> On Wed, 26 Jan 2005 11:50:46 -0800, snacktime <snacktime at gmail.com> wrote:
> 
>>I'm trying to figure out why the following code transforms ascii STX
>>(control-b) into "\x82".  The perl module I use returns a value of
>>"^B", and that is also what the application I am communicating with
>>expects to see.  Some ascii characters such as FS and GS come through
>>fine, but STX and ETX get transformed incorrectly (at least for what I
>>need they do).

I didn't see the first post, which you quoted above... more newsfeed
or python-list misalignment I guess. :-(

Anyway, since STX '\x02' has only one bit set, if you are setting
the parity bit for "even" parity, then naturally it will be set
(in order to make the total number of "on" bits an even number),
so you get '\x82' (which has two bits set).  ETX, on the other
hand '\x03' already has two bits set, so the high bit is left alone.

It sounds as though you need to examine the specification
for the receiving system in more detail, or perhaps seek
clarification from the other party involved in this system
you're working with.  If you have examples that show STX and
ETX both being transmitted, around other data which itself
has had the parity bit set for even parity, then clearly (a)
the folks involved in designing that system are idiots
<0.5 wink> and (b) you'll have to modify the way you are
forming the transmission packet.  It appears they may want
the STX/ETX pair to be sent without being affected by the
parity process...

-Peter



More information about the Python-list mailing list