Shop OBEX P1 Docs P2 Docs Learn Events
parity checking scheme,,, — Parallax Forums

parity checking scheme,,,

ArchiverArchiver Posts: 46,084
edited 2000-04-15 00:02 in General Discussion
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...

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-04-14 19:14
    One solution:

    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...
  • ArchiverArchiver Posts: 46,084
    edited 2000-04-15 00:02
    You can do parity with a state machine, no matching, no math:

    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...
    >
    >
    >
    >
    >
Sign In or Register to comment.