Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
52 views4 pages

Cn-Lab - Task-1 A&b

The document discusses two data link layer framing methods - bit stuffing and character stuffing. Bit stuffing involves adding extra bits to transmitted data to detect frame boundaries reliably. Character stuffing adds special characters to mark frame start and end for reliable interpretation by the receiver.

Uploaded by

metan39217
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

Cn-Lab - Task-1 A&b

The document discusses two data link layer framing methods - bit stuffing and character stuffing. Bit stuffing involves adding extra bits to transmitted data to detect frame boundaries reliably. Character stuffing adds special characters to mark frame start and end for reliable interpretation by the receiver.

Uploaded by

metan39217
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

TASK-1

Implement the following data link layer framing methods

A) Bit stuffing

Procedure:
Bit stuffing is a widely used technique in digital communication to ensure reliable
data transmission. In simple terms, bit stuffing involves adding extra bits to the transmitted
data to ensure that the receiver can accurately detect the start and end of the data frame. This
technique is particularly useful in situations where data frames are transmitted over
unreliable channels, such as wireless networks or noisy copper wires. In this article, we will
discuss bit stuffing in C programming language and how it can be implemented using
bitwise operators.
The basic concept of bit stuffing is straightforward. The sender of the data frame
adds an extra bit after every sequence of five consecutive 1s in the data being transmitted.
This added bit is always a 0 and does not interfere with the actual data being transmitted.
The receiver of the data frame then looks for this sequence of six consecutive 1s, which
indicates the start of a data frame. The receiver then extracts the data from the frame,
removes the extra 0s, and processes the data as normal. The process of adding and removing
extra bits is known as bit stuffing and de-stuffing, respectively.

Program:

#include<stdio.h>
#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)
{
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: 010111111001

After Bit Stuffing : 0101111101001


B) Character stuffing

Procedure:

Character stuffing is a technique used in computer programming to control data


transmission between different systems or devices. It involves adding special
characters or sequences of characters to the data being transmitted to mark the
beginning and end of a data frame. This article will explore character stuffing and
how it can be implemented in the C programming language.
Character stuffing is commonly used in data communication protocols to
ensure the receiving system correctly interprets the transmitted data. It helps frame
the data so that the receiver can easily identify the start and end of each data frame.
One common use case of character stuffing is serial communication, where data is
transmitted one bit at a time over a communication channel.

Program:

#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.

You might also like