newbie sending hex values over UDP socket
fluxent at yahoo.com
Thu Sep 16 15:50:09 CEST 2004
Grant Edwards <grante at visi.com> wrote in message news:<4147408f$0$65608$a1866201 at newsreader.visi.com>...
> On 2004-09-14, Bill Seitz <fluxent at yahoo.com> wrote:
> >> Excellent - now how about calculating a parity-check byte?
> > Here's the definition of the parity byte:
> > The column parity is one (1) byte. The eight bits of data in this
> > byte re¬flect the odd parity of all corresponding bits in the block;
> > i.e. bit 8 of the Column Parity byte is the odd parity of all bit 8's
> > in the entire block.
> > Column parity will be calculated by the sender as follows:
> > (a) Begin with the value 255.
> > (b) Exclusive OR the current value with the value of the first (or
> > next) data byte beginning with the header byte. Repeat until all
> > bytes up to, but not includ¬ing, the parity byte have been used.
> > (c) Send the result in the column parity position.
> # assume "s" is the data for which we want a parity byte
> parityByte = chr(reduce(operator.__xor__,map(ord,s)))
oy, I've never dug into the whole reduce thing. I ended up looping
through a series of '^' operations, which seems to work OK.
Now how about a checksum calc?
"The additive checksum (modulo-65536) of all bytes from the [STX] byte
to the last data byte, inclusive. (not including checksum)"
Just use a modulus '%'?
More information about the Python-list