From: John Payson

comments from Andrew
Warren of Fast Forward
Engineering

;This routine will leave the parity of X in X.0 ;while blenderizing most of the rest of X mov W, <>X ;x = abcdefgh w = efghabcd xor X, W ;x = abcdefgh w = efghabcd ; xor efghabcd mov W, >>X ;x = abcdefgh w = -abcdefg ; xor efghabcd xor -efghabc xor X, W ;x = abcdefgh w = -abcdefg ; xor efghabcd xor -efghabc ; xor -abcdefg ; xor -efghabc ; at this point, the parity for half the bits ; (a, b, e, and f) is in bit 2 of X, and the ; parity for the other half (bits c, d, g, and h) ; is in bit 0 of X. snb X.2 ; if the parity of (a,b,e,f) is 0, ; then the parity of (a,b,c,d,e,f,g,h) ; is equal to the parity of (c,d,g,h)... ; which is already in bit 0, so skip ahead. inc X ; otherwise, the parity of (a,b,e,f) is 1, ; so the parity of (a,b,c,d,e,f,g,h) is ; NOT equal to the parity of (c,d,g,h). ; invert bit 0. ; at this point, bit 0 contains the parity of ; (a,b,c,d,e,f,g,h).

Kübek Tony [tony.kubek at FLINTAB.COM] says

;++++++++++++ ; ; CALC_PARITY - Calculates parity of one byte, content is trashed, result in lowest bit ; There '1' means ODD and '0' means EVEN ; CALC_PARITY MACRO ARG_BYTE SWAPF ARG_BYTE, W XORWF ARG_BYTE, F RRF ARG_BYTE, W XORWF ARG_BYTE, F BTFSC ARG_BYTE, 2 INCF ARG_BYTE, F ENDMFirst save the parity bit,either the 8'th bit in 7 bit comms. or the 9'th in 8 bit comms ( with parity ).

In the case of 7 bit comms do not forget to clear it prior to using the macro below.

Using for example 7 data bits even parity, the parity bit ( 8'th bit ) should always make sure that totally the byte will have an even number of bits.

So ( excluding the parity bit of cource ) maybe you have 3 [ones] bit in the received byte, then the parity bit is ( should be :-) ) set to '1', to achive an even number of bits.

Olin Lathrop [olin at cognivis.com], http://www.cognivis.com says:

Parity is a one-bit checksum for a string of bits. There are two kinds of parity, even and odd. Even parity is the one-bit sum of all the bits, and odd parity is the complement of that. A one-bit sum means the addition is carried out in a one-bit word, which is the same as the least significant bit of an addition using a larger word. This low bit therefore only indicates whether the sum was odd (1) or even (0). Therefore the even parity is 0 iff there are an even number of 1 bits in the string of bits being tested.Note that one-bit addition is the same as XOR (make a truth table for addition and XOR if you're not conviced), so even parity can also be thought of as the XOR of all the bits being tested. That is how the compact example apparently from John Payson worked. First the high and low nibbles were XORed. Each bit in each nibble is now the parity of itself and the same bit in the other nibble. In other words, this reduces the problem to finding the parity of one of the nibbles. This value is XORed again with itself shifted right one bit. Bits 0 and 2 are now the parity of the upper and lower half of the nibbles. Bit 0 is then incremented if bit 2 is set, creating the combined parity in bit 0.

ODD parity is most useful for serial transmission like RS-232. This guarantees that each 9 bit word (8 data bits, 1 parity bit) sent contains at least one 0 bit and at least one 1 bit, which means all zeros or all ones is definitely an error condition. Parity isn't used as much today because it can only detect single bit errors. Most communications systems tend to use checksums for blocks of data with some sort of ACK/NACK higher level protocol.

file: /Techref/scenix/lib/math/bit/parity_sx.htm, 4KB, , updated: 2013/7/22 17:16, local time: 2022/11/27 23:47, |

©2022 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?<A HREF="http://www.sxlist.com/techref/scenix/lib/math/bit/parity_sx.htm"> SX Microcontroller Bit Math Method Parity</A> |

Did you find what you needed? |

## Welcome to sxlist.com!sales, advertizing, & kind contributors
just like you! Please don't rip/copy
(here's why Copies of the site on CD are available at minimal cost. |

## Welcome to www.sxlist.com! |

.