parity checking scheme,,,
Archiver
Posts: 46,084
Greetings all,
I have a stamp2sx that is set up to read a hex address in the range
of 00 - FF on pins 0 - 7. After reading the address I have a need to
determine the parity of the address, even or odd so I can set a 9th
parity bit to maintain odd parity. At the present time my idea is to
set up a table with all the even possibilities (approx 128 of them)
and do a compare. I was wondering if anyone could suggest something
a little more clever with a lot less code. Thanks
kjomara@a...
I have a stamp2sx that is set up to read a hex address in the range
of 00 - FF on pins 0 - 7. After reading the address I have a need to
determine the parity of the address, even or odd so I can set a 9th
parity bit to maintain odd parity. At the present time my idea is to
set up a table with all the even possibilities (approx 128 of them)
and do a compare. I was wondering if anyone could suggest something
a little more clever with a lot less code. Thanks
kjomara@a...
Comments
parity VAR BIT
parity = IN0 ^ IN1 ^ IN2 ^ IN3 ^ IN4 ^ IN5 ^ IN6 ^ IN7
Even parity on input pins gives parity = 0. Odd parity on input pins
yields parity = 1.
Steve
On 14 Apr 00 at 15:52, kjomara@a... wrote:
> Greetings all,
> I have a stamp2sx that is set up to read a hex address in the range
> of 00 - FF on pins 0 - 7. After reading the address I have a need
> to determine the parity of the address, even or odd so I can set a
> 9th parity bit to maintain odd parity. At the present time my idea
> is to set up a table with all the even possibilities (approx 128 of
> them) and do a compare. I was wondering if anyone could suggest
> something a little more clever with a lot less code. Thanks
>
> kjomara@a...
odd parity (even parity starts with parity bit = 0)
pbit var bit
Start with parity bit = 1
for bit = 0 to 7
if bit = 1 AND parity = 1 then parity = 0
if bit = 1 AND parity = 0 then parity = 1
next bit
OR even easier
pbit var bit
Start with parity bit = 1
for bit = 0 to 7
add bit to pbit
next
With only a single bit, even bits will overflow leaving pbit = 0.
DLC
> Greetings all,
> I have a stamp2sx that is set up to read a hex address in the range
> of 00 - FF on pins 0 - 7. After reading the address I have a need to
> determine the parity of the address, even or odd so I can set a 9th
> parity bit to maintain odd parity. At the present time my idea is to
> set up a table with all the even possibilities (approx 128 of them)
> and do a compare. I was wondering if anyone could suggest something
> a little more clever with a lot less code. Thanks
>
> kjomara@a...
>
>
>
>
>