Parity works by setting the high bit to 1 when there are an even number of bits in the number, and 0 if there are odd bits.
int c = 0;
for (int i = 0; i < sizeof(byte) - 1; i++) // Minus 1 because we don't care about high bit
{
if (mybyte & (1 << i))
c++; /* cheap shot at C#, sorry :-) */
}
if (c & 0x01)
mybyte |= 0x80; // Even parity
else
mybyte &= 0x7f; // Odd parity
This is just psuedo code, of course, but should clear up your approach.
Bryan Wilcutt