Coders Packet

Implement framing technique - Bit stuffing using HTML,JavaScript & C

By Parul Lohia

It is the process of inserting non-information bits into data to break up bit patterns to affect the synchronous transmission of information. For the UI HTML& CSS are used.

Bit stuffing is a synchronization technique that involves inserting/stuffing one or many non-information bits into a message to break overall message sequencing. The physical layer's stream of bits is split into data frames in the Data Link layer. The length of the data frames can be fixed or changeable. The size of each frame to be transmitted may be changeable in variable-length framing. The size of each frame to be sent may differ in variable-length framing. As a result, a pattern of bits is utilized as a delimiter (a character that indicates the start or end of a unit of data) to distinguish between one frame and the next. If the pattern appears in the message, then, measures must be implemented to avoid this circumstance.

 
 
 
 
Bit Manipulation

Enter Input
 
 
 

function stuffing(data){
var bit = document.getElementById("bit").value; var count = 0; 
var ans = ""; 
for (let index = 0; index < bit.length; index++) { if(bit.charAt(index) == '0'){ 
count = 0; 
}else{ 
count++; 
} 
ans = ans+bit.charAt(index); 
if(count == 5){ 
ans = ans + '0'; 
count = 0; 
} 
} 
document.getElementById("res").value = "Stuffed - " + ans; } 
function destuffing(data){ 
var bit = document.getElementById("bit").value; var count = 0;
var ans = ""; 
for (let index = 0; index < bit.length; index++) { if(bit.charAt(index) == '0'){ 
if(count==5){ 
count = 0; 
continue; 
} 
count = 0; 
}else{ 
count++; 
} 
ans = ans+bit.charAt(index); 
} 
document.getElementById("res").value = "Destuffed - "+ ans; } 
#include 
#include 
int main() 
{ 
char *a,*b; 
char temp; 
char in[100]; 
char stuff[100]; 
char destuff[100]; 
int count=0; 
printf("enter the input character string (0‘s and 1‘s only):\n"); 
scanf("%s",in); 
a=in; 
b=stuff; 
while(*a!='\0')
{ 
if(*a=='0') 
{ 
*b=*a; 
b++; 
a++; 
} 
else 
{ 
while(*a=='1' && count!=5) 
{ 
count++; 
*b=*a; 
b++; 
a++; 
} 
if(count==5) 
{ 
*b='0'; 
b++; 
} 
count=0; 
} 
} 
*b='\0'; 
printf("\nthe stuffed character string is"); printf("\n%s",stuff); 
a=stuff; 
b=destuff; 
while(*a!='\0') 
{ 
if(*a=='0') 
{ 
*b=*a; 
b++; 
a++; 
} 
else 
{ 
while(*a=='1' && count!=5) 
{
count++; 
*b=*a; 
b++; 
a++; 
} 
if(count==5) 
{ 
a++; 
} 
count=0; 
} 
} 
*b='\0'; 
printf("\nthe destuffed character string is"); 
printf("\n%s\n",destuff); 
return 0; 
} 

Output:

Download project

Reviews Report

Submitted by Parul Lohia (lohiaparul)

Download packets of source code on Coders Packet