Algorithm for hamming or parity bit calculation?

1.9k views Asked by At

i'm trying to write a program to find hamming code in java ,but have a slight confusion regarding hamming code calculation ,

Below is what most tutorials say,

Example :For a n bit message, say 8 bit message we require k=4 parity or hamming bits placed in positions of powers of 2( numbered 1 to k+n from right to left ), see below example

8 bit message =11000100 
k=4

hence

Bit position         12   11  10   9    8     7     6   5    4   3    2    1
                     d     d   d   d    P8    d     d   d   P4   d    P2   P1  

where P1...P4 are the parity bits

Next ,to calculate the value of the parity bits the instruction tells me to blindly do this

Each parity bit is calculated as follows:

    P1 = XOR of bits (3, 5, 7, 9, 11)   =   1⊕1⊕0⊕0⊕0 = 0
    P2  =XOR of bits (3, 6, 7, 10, 11) =   1⊕0⊕0⊕1⊕0 = 0
    P4  =XOR of bits (5, 6, 7, 12)      =   1⊕0⊕0⊕0 = 1
    P8  =XOR of bits (9, 10, 11, 12)   =   0⊕1⊕0⊕0 = 1

Is there some method to do this , or should i just memorize this ?based on what do they arrive at XOR(3,5...etc).Some kind of an algorithm for it?

NOTE: To write a Java program to find hamming code for any n bit number i require an explanation to this, so i hope the question qualifies in Stack-overflow

0

There are 0 answers