Calculating parity of a binary number
hi,
i have external device sends binary data arduino 16 bits @ time. of these 16 bits, first bit parity of next 7 bits while last bit odd parity previous 7 bits. have idea of how in head loop , few conditionals don't quite understand how in wiring. can me?
thanks in advance
i have external device sends binary data arduino 16 bits @ time. of these 16 bits, first bit parity of next 7 bits while last bit odd parity previous 7 bits. have idea of how in head loop , few conditionals don't quite understand how in wiring. can me?
thanks in advance

by "do this" assume mean check parity?
here's potential starting point:
efficiencies can realized in above more clear efficient
--
the gadget shield: accelerometer, rgb led, ir transmit/receive, light sensor, potentiometers, pushbuttons
here's potential starting point:
code: [select]
unsigned thevalue; // 16-bit value external device
// i'm assuming "first bit" lsb , "last bit" msb
unsigned evenparity = (thevalue & (1<<0)) ? 1 : 0;
unsigned oddparity = (thevalue & (1<<15)) ? 1 : 0;
unsigned firstparity, secondparity, bit;
// compute parity on first set of 7 bits past parity bit
for (bit=1, firstparity=0; bit < 8; bit++) {
firstparity ^= (thevalue & (1<<bit)) ? 1 : 0;
}
// compute parity on next set of 7 bits
for (bit=8, secondparity=0; bit < 15; bit++) {
secondparity ^= (thevalue & (1<<bit)) ? 1 : 0;
}
// comparisons of firstparity vs. evenparity , secondparity vs. oddparity
efficiencies can realized in above more clear efficient

--
the gadget shield: accelerometer, rgb led, ir transmit/receive, light sensor, potentiometers, pushbuttons
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Calculating parity of a binary number
arduino
Comments
Post a Comment