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.
Block parity |
Theory
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, the data:
1, 4, 12, –1, –6, 17, 0, –10
would be arranged as:
1 0000 0001 4 0000 0100 12 0000 1100 –1 1111 1111 –6 1111 1010 17 0001 0001 0 0000 0000 –10 1111 0110 --------- 1110 1011
It can be seen that modulo-2 addition is 1110 1011 (which is –21 in decimal). Thus the transmitted data would be:
0000 0001 0000 0100 0000 1100 1111 1111 1111 1010 0001 0001 0000 0000 1111 0110 1110 1011 ...
In this case, a single error will cause the checksum to be wrong. Unfortunately, as with simple parity, even errors in the same column will not show-up an error, but single errors in different columns will show up as an error. Normally when errors occur, they are either single-bit errors or large bursts of errors. With a single-bit error, the scheme will detect an error and it is also likely to detect a burst of errors, as the burst is likely to affect several columns and also several rows.
This error scheme is used in many systems as it is simple and can be implemented easily in hardware with XOR gates or simply calculated with appropriate software. The more symbols that are used in the block, the more efficient the code will be. Unfortunately, when an error occurs the complete block must be retransmitted.
Code
The code is:
import sys inp='1, 4, 12, -1, -6, 17, 0, -10' if (len(sys.argv)>1): inp=str(sys.argv[1]) def tohex(val, nbits): return hex((val + (1 << nbits)) % (1 << nbits)) def get_parity_block(inp_val): running_total=int(inp_val[0]) for i in range(1,len(inp_val)): running_total^=int(inp_val[i]) return running_total def show_code(inp_val,res): for i in range(0,len(inp_val)): print inp_val[i],"-",tohex(int(inp_val[i]),8) print res,"-",tohex(res,8)," <-- Parity block" return inp_values = inp.replace(' ','').split(",") print "Input: ",inp_values res=get_parity_block(inp_values) print "" print "Block parity value:\t",res print "Block parity (hex):\t",tohex(res,8) print "\nData Block:" show_code(inp_values,res)