Block parity is a block code which adds a parity symbol to the end of a block of code. In this example we calculate the odd parity value for the block:
Block parity |
Example
Block parity is a block code which adds a parity symbol to the end of a block of code. For example a typical method is to transmit the one’s complement (or sometimes the two’s complement) of the modulo-2 sum of the transmitted values. Using this coding, and a transmitted block code after every 8 characters, a sample run is:
00000001 00000100 00001100 11111111 11111010 00010001 00000000 11110110 -------- 11101011 -------- Even parity: 11101011 Odd parity: 00010100
Coding
The following defines the code:
import sys val1="00000001, 00000100,00001100,11111111,11111010,00010001, 00000000, 11110110" if (len(sys.argv)>1): val1=sys.argv[1] val1=val1.replace(' ','') vals = val1.split(',') running_val = int(vals[0],2) print vals[0] for x in range(1,len(vals)): print vals[x] running_val = (int(vals[x],2) ^ running_val) & 0xff print "--------" print bin(running_val)[2:].zfill(8) print "--------" print print "Even parity: ",bin(running_val)[2:].zfill(8) running_val = ~(running_val) & 0xff print "Even parity: ",bin(running_val)[2:].zfill(8)