hammimng code
hammimng code
and correct error as well by itself. Hamming code is a set of error-correction codes that can be used
to detect and correct the errors that can occur when the data is moved or stored from the sender to
the receiver. General Algorithm of Hamming code – The Hamming Code is the use of extra parity bits
to allow the identification of an error.
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
4. Each data bit is included in a unique set of parity bits, as determined its bit pos
• Parity bit 1 covers all the bits positions whose binary representation includes a 1 in the least
significant position (1, 3, 5, 7, 9, 11, etc).
• Parity bit 2 covers all the bits positions whose binary representation includes a 1 in the second
position from the least significant bit (2, 3, 6, 7, 10, 11, etc).
• Parity bit 4 covers all the bits positions whose binary representation includes a 1 in the third
position from the least significant bit (4–7, 12–15, 20–23, etc).
• Parity bit 8 covers all the bits positions whose binary representation includes a 1 in the fourth
position from the least significant bit bits (8–15, 24–31, 40–47, etc
• In general each parity bit covers all bits where the bitwise AND of the parity position and the bit
position is non-zero. Parity check is done for even parity, hence set a parity bit to 1 if the total
number of ones in the positions it checks is odd. Set a parity bit to 0 if the total number of ones in
the positions it checks is even.
This time (i.e. the time joining message transmitting and acknowledgement receiving) is the
sender’s waiting time, and the sender is idle during this time.
When the sender gets the acknowledgement (ACK), it will send the next data packet to the
receiver and wait for the disclosure again, and this process will continue as long as the sender
has the data to send.
While sending the data from the sender to the receiver, the data flow needs to be controlled.
If the sender is transmitting the data at a rate higher than the receiver can receive and
process it, the data will get lost.
The Flow-control methods will help in ensuring that the data doesn't get lost. The flow control
method will check that the senders send the data only at a rate that the receiver can receive
and process. The working of Stop and Wait Protocol is shown in the figure b below:
#include<stdio.h>
int sender();
int recv();
int timer=0,wait_for_ack=-1,frameQ=0,cansend=1,t=0;
main()
{
int i,j;
int frame[5];
if(i==frame[t])
{
frameQ++;
t++;
}
if(frameQ==0)
printf("NO FRAME TO SEND at time=%d \n",i);
{
printf("FRAME SEND AT TIME=%d\n",i);
cansend=-1;
frameQ--;
timer++;
printf("timer in sender=%d\n",timer);
}
if(frameQ>0 && cansend==-1)
printf("FRAME IN Q FOR TRANSMISSION AT TIME=%d\n",i);
if(frameQ>0)
t++;
}
printf("frameQ=%d\n",frameQ);
printf("i=%d t=%d\n",i,t);
printf("value in frame=%d\n",frame[t]);
return 0;
}
int recv(int i )
{ printf("timer in recvr=%d\n",timer);
if(timer>0)
{
timer++;
}
if(timer==3)
{
printf("FRAME ARRIVED AT TIME= %d\n",i);
wait_for_ack=0;
timer=0;
}
else
printf("WAITING FOR FRAME AT TIME %d\n",i);
return 0;
}
}