CN Lab Exp 1 To 6
CN Lab Exp 1 To 6
CN Lab Exp 1 To 6
ALGORITHM:
Step-1:start
Step-4: Check the string whether it has 5 consecutive 1’s except the
appending string.
Step-5:If yes,insert’0’ bit as stuff in the next bit,else transmit the next
bit.
Step-10:If yes then remove the next bit i.e.do not transmit the next bit
else transmit the data.
Step-13:stop.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
Void main()
int a[20],b[30],I,j,k,count,n;
clrscr();
scanf(“%d”,&n);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
i=0;
count=1;
j=0;
while(i<n)
if(a[i]==1)
b[j]=a[i];
for(k=i+1;a[k]==1&&k<n&&count<5;k++)
j++;
b[j]=a[k];
count++;
if(count==5)
j++;
b[j]=0;
i=k;
}
else
b[j]=a[i];
i++;
j++;
for(i=0;i<j;i++)
printf(“%d”,b[i]);
getch();
INPUT-1:
1
1
OUTPUT-1:
INPUT-2:
OUTPUT-2:
ALGORITHM:
Step-1:start.
Step-5:If yes then insert the string ‘DLE’ before the character else
transmit the next character.
Step-10:if yes the remove the string ‘DLE’ that is encounterd first else
transmit the data.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
Void main()
char a[30],b[4]=”dle”;
int i,j,count=0,n,p;
scanf(“%s”,a);
n=strlen(a);
printf(“length is %d\n”,n);
printf(“dle stx”);
for(i=0;i<n;i++)
count=0;
p=i;
for(j=0;j<3;j++)
count=0;
p=i;
for(j=0;j<3;j++)
if(a[i]==b[j])
count=count+1;
i++;
if(count!=3)
i=p;
}
if(count==3)
printf(“dledle”);
else
printf(“%c”,a[i]);
printf(“dleetx\n”);
printf(“%s”,a);
getch();
INPUT:
length is 5
The actual procedure which yields the checksum, given a data input is called
a checksum function or checksum algorithm.
Given data input, the actual process of generating a checksum is called a
checksum function or checksum algorithm.
Checksum method can only detect errors but is unable to correct the error.
The checksum method can only detect errors, but cannot correct them.
For the purpose of this program we are finding checksum for 2 binary strings.
If both bits are 0 and carry is 0, sum=0 and carry=0 If both bits are
0 and the carry is 0, then sum = 0 and carry = 0
If both bits are 0 and carry is 1,sum=1 and carry=0 If both bits are
0 and carry is 1, sum = 1 and carry = 0
If both bits are 1 and carry is 0,sum=0 and carry=1 If both bits are
1 and the carry is 0, then sum = 0 and carry = 1
If both bits are 1 and carry is 1,sum=1 and carry=1 If both bits are
1 and the carry is 1, sum = 1 and carry = 1
If either bit is 1 and carry is 0,sum=1 and carry=0 If any bit is 1
and carry is 0, sum = 1 and carry = 0
If either bit is 1 and carry is 1,sum=0 and carry=1 If any bit is 1
and carry is 1, sum = 0 and carry = 1
While doing the addition we have to add the binary strings from
rightmost end i.e LSB to MSB. When adding, we must add a binary
string from the rightmost end (that is, LSB) to the MSB.
When binary sum is done 1's complement of it is taken by reversing 1's
to 0's and vice versa. When the binary sum is completed, by inverting 1
to 0, and vice versa, one's complement can be obtained.
The resulting 1's complement is the Checksum. The resulting 1's
complement is the checksum.
Stop. stop.
C language checksum program (Checksum Program in C)
#include<stdio.h>
#include<string.h>
int main()
char a[20],b[20];
char sum[20],complement[20];
int i,length;
scanf("%s",&a);
scanf("%s",&b);
if(strlen(a)==strlen(b)){
length = strlen(a);
char carry='0';
for(i=length-1;i>=0;i--)
{
{
sum[i]='0';
carry='0';
}
{
sum[i]='1';
carry='0';
}
{
sum[i]='1';
carry='0';
}
{
sum[i]='0';
carry='1';
}
{
sum[i]='1';
carry='0';
}
{
sum[i]='0';
carry='1';
}
{
sum[i]='0';
carry='1';
}
{
sum[i]='1';
carry='1';
}
else
break;
}
printf("\nSum=%c%s",carry,sum);
for(i=0;i<length;i++)
{
if(sum[i]=='0')
complement[i]='1';
else
complement[i]='0';
}
if(carry=='1')
carry='0';
else
carry='1';
printf("\nChecksum=%c%s",carry,complement);
else {
}
}
Output:
Enter first binary string
10101
11001
Sum=101110
Checksum=010001
Algorithm:
#include <math.h>
#include <stdio.h>
// If current boit is 1
if (code[j] == 1)
count++;
}
// Update i
i = i + 2 * position;
}
if (count % 2 == 0)
return 0;
else
return 1;
}
// Function to calculate hamming code
void solve(int input[], int n)
{
int i, p_n = 0, c_l, j, k;
i = 0;
c_l = p_n + n;
j = k = 0;
// Driver Code
void main()
{
// Given input message Bit
input[0] = 0;
input[1] = 1;
input[2] = 1;
input[3] = 1;
int N = 4;
// Function Call
solve(input, N);
}
Output:
The generated Code Word is: 0001111
Computer Network,
Program Algorithm/Flowchart:
Begin
Step 1:Declare I, j , fr[8], dupfr[11], recfr[11], tlen, flag,
gen[4], genl, frl, rem[4] as integer
Step 2: initialize frl=8 and genl=4
Step 3: initialize i=0
Step 4: Repeat step(5to7) until i<frl
Step 5: read fr[i]
Step 6: dupfr[i]=fr[i]
Step 7: increment i
Step 8: initialize i=0
Step 9: repeat step(10to11) until i<genl
Step 10: read gen[i]
Step 11: increment i
Step 12: tlen=frl+genl-1
Step 13: initialize i=frl
Step 14: Repeat step(15to16) until i<tlen
Step 15: dupfr[i]=0
Step 16: increment i
Step 17: call the function remainder(dupfr)
Step 18: initialize i=0
Step 19: repeat step(20 to 21) until j<genl
Step 20: recfr[i]=rem[j]
Step 21: increment I and j
Step 22: call the function remainder(dupfr)
Step 23: initialize flag=0 and i=0
Step 24: Repeat step(25to28) until i<4
Step 25: if rem[i]!=0 then
Step 26: increment flag
Step 27: end if
Step 28: increment i
Step 29: if flag=0 then
Step 25: print frame received correctly
Step 25: else
Step 25: print the received frame is wrong
End
Function: Remainder(int fr[])
Begin
Step 1: Declare k,k1,I,j as integer
Step 2: initialize k=0;
Step 3: repeat step(4 to 14) until k<frl
Step 4: if ((fr[k] == 1) then
Step 5: k1=k
Step 6: initialize i=0, j=k
Step 7: repeat step(8 to 9) until i<genl
Step 8: rem[i] =fr[j] exponential gen[i]
Step 9: increment I and j
Step 10: initialize I = 0
Step 11: repeat step(12to13) until I <genl
Step 12: fr[k1] = rem[i]
Step 13: increment k1 and i
Step 14: end if
End
Program Output:
Enter frame: MLRITM
Enter generator: frame received correctly
------------------
(program exited with code: 24)
Press return to continue
With sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by
the receiver
12 5 89
Acknowledgement of above frames sent is received by sender
46
Acknowledgement of above frames sent is received by sender