0% found this document useful (0 votes)
44 views10 pages

Computer Networks Record: Pojit

The document discusses implementing cyclic redundancy code (CRC) to detect errors in digital data transmission. It includes a C program that takes a data string and divisor as input, performs CRC encoding to generate a code word by appending the remainder bits, transmits the code word, and then performs CRC checking on the received code word to detect any errors. The program outputs whether the transmission was successful or contained errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views10 pages

Computer Networks Record: Pojit

The document discusses implementing cyclic redundancy code (CRC) to detect errors in digital data transmission. It includes a C program that takes a data string and divisor as input, performs CRC encoding to generate a code word by appending the remainder bits, transmits the code word, and then performs CRC checking on the received code word to detect any errors. The program outputs whether the transmission was successful or contained errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Computer Networks

Record

Pojit
Task 1
Dijkstra’s Algorithm
Aim: Program to implement dijkstra’s algorithm
Program:
/*20711A0595*/

#include<stdio.h>
void main()
{
int path[5][5],i, j, min, a[5][5],p, st=1,ed=5,stp,edp,t[5],index;
printf("Enter the cost matrix\n");
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d", &a[i][j]);
printf("Enter the paths\n");
scanf("%d", &p);
printf("Enter possible paths\n");
for(i=1;i<=p; i++)
for(j=1;j<=5;j++)
scanf("%d", &path[i][j]);
for(i=1;i<=p; i++)
{
t[i]=0;
stp=st;
for(j=1;j<=5;j++)
{
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else
stp=edp;
}
}
min=t[st];index=st;
for(i=1;i<=p; i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}
printf("Minimum cost %d", min);
printf("\n Minimum cost path ");
for(i=1;i<=5;i++)
{
printf("--> %d", path[index][i]);
if(path[index][i]==ed)
break;
}
}
OUTPUT:
Enter the cost matrix
01234
12345
43210
54321
01234
Enter the paths
2
Enter possible paths
01234
543 21
Minimum cost 6
Minimum cost path 0123Enter the cost matrix
TASK 2
Bit Stuffing
Aim: C Program to implement bit stuffing
Program:
/*20711A0595*/

#include<string.h>
int main()
{
    int a[20],b[30],i,j,k,count,n;
    printf("Enter frame size (Example: 8):");
    scanf("%d",&n);
    printf("Enter the frame in the form of 0 and 1 :");
    for(i=0; i<n; i++)
        scanf("%d",&a[i]);
    i=0;
    count=1;
    j=0;
    while(i<n)
    {
        if(a[i]==1)
    #include<stdio.h>
    {
            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++;
    }
    printf("After Bit Stuffing :");
    for(i=0; i<j; i++)
        printf("%d",b[i]);
    return 0;
}

Output:
Enter frame size (Example: 8):12
Enter the frame in the form of 0 and 1 :0 1 0 1 1 1 1 1 1 0 0 1
After Bit Stuffing :0101111101001
Task 3
Byte Stuffing

Aim:To implement byte stuffing


Program:
/*20711A0595*/

#include<stdio.h>
#include<string.h>
main()
{
char a[30], fs[50] = " ", t[3], sd, ed, x[3], s[3], d[3], y[3];
int i, j, p = 0, q = 0;
clrscr();
printf("Enter characters to be stuffed:");
scanf("%s", a);
printf("\nEnter a character that represents starting delimiter:");
scanf(" %c", &sd);
printf("\nEnter a character that represents ending delimiter:");
scanf(" %c", &ed);
x[0] = s[0] = s[1] = sd;
x[1] = s[2] = '\0';
y[0] = d[0] = d[1] = ed;
d[2] = y[1] = '\0';
strcat(fs, x);
for(i = 0; i < strlen(a); i++)
{
t[0] = a[i];
t[1] = '\0';
if(t[0] == sd)
strcat(fs, s);
else if(t[0] == ed)
strcat(fs, d);
else
strcat(fs, t);
}
strcat(fs, y);
printf("\n After stuffing:%s", fs);
getch();
}
Output:-

Enter characters to be stuffed: goodday


Enter a character that represents starting delimiter: d
Enter a character that represents ending delimiter: g
After stuffing: dggooddddayg
TASK 4
Cyclic Redundancy Code(CRC)
Aim: To implement Cyclic Redundancy Code
Program:
/*20711A0595*/

#include<stdio.h>
char data[20],div[20],temp[4],total[100];
int i,j,datalen,divlen,len,flag=1;
void check();
int main()
{
printf("Enter the total bit of data:");
scanf("%d",&datalen);
printf("\nEnter the total bit of divisor");
scanf("%d",&divlen);
len=datalen+divlen-1;
printf("\nEnter the data:");
scanf("%s",&data);
printf("\nEnter the divisor");
scanf("%s",div);
for(i=0;i<datalen;i++)
{
total[i]=data[i];
temp[i]=data[i];
}
for(i=datalen;i<len;i++) //padded with
zeroes corresponding to divlen
total[i]='0';
check();
// check for crc
for(i=0;i<divlen;i++) // append crc output
(remainder) at end of temp
temp[i+datalen]=data[i];
printf("\ntransmitted Code Word:%s",temp);
printf("\n\nEnter the received code word:");
scanf("%s",total);
check();
for(i=0;i<divlen-1;i++)
if(data[i]=='1')
{
flag=0;
break;
}
if(flag==1)
printf("\nsuccessful!!");
else
printf("\nreceived code word contains errors...\n");
}
void check()
{
for(j=0;j<divlen;j++)
data[j]=total[j];
while(j<=len)
{
if(data[0]=='1') // in XOR ans remains as it
is except in case of 1
for(i = 1;i <divlen ; i++)
data[i] = (( data[i] == div[i])?'0':'1');
for(i=0;i<divlen-1;i++) // left shift data word by 1
after div
data[i]=data[i+1];
data[i]=total[j++]; // replace empty
right by total
}
}
Output:
Enter the total bit of data:7

Enter the total bit of divisor4

Enter the data:1001010

Enter the divisor1011

transmitted Code Word:1001010111

Enter the received code word:1001010100

received code word contains errors...

You might also like