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

Ex 3 NW

The document discusses bit stuffing and destuffing and character stuffing and destuffing techniques for data transmission. It first explains a Java program that performs bit stuffing on a binary string by inserting a 0 bit after every 5 consecutive 1 bits in the string. It then performs destuffing on the stuffed string by removing the extra 0 bit inserted after every 5 1 bits. It then discusses another Java program that performs character stuffing on a string by inserting "dle" after every occurrence of the substring "dle" in the string. It performs destuffing by removing the extra "dle" strings inserted during stuffing.

Uploaded by

727822tuit204
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)
33 views4 pages

Ex 3 NW

The document discusses bit stuffing and destuffing and character stuffing and destuffing techniques for data transmission. It first explains a Java program that performs bit stuffing on a binary string by inserting a 0 bit after every 5 consecutive 1 bits in the string. It then performs destuffing on the stuffed string by removing the extra 0 bit inserted after every 5 1 bits. It then discusses another Java program that performs character stuffing on a string by inserting "dle" after every occurrence of the substring "dle" in the string. It performs destuffing by removing the extra "dle" strings inserted during stuffing.

Uploaded by

727822tuit204
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

BIT Stuffing and Destuffing

import java.util.*;
public class bit_stuffing
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the message:-");
String d1 = sc.nextLine();
String remaining = new String();
String output=new String();
int counter = 0;
for(int i=0;i<d1.length();i++)
{
if (d1.charAt(i)!='1' && d1.charAt(i)!='0')
{
System.out.println("Enter valid Binary values");
return;
}
if(d1.charAt(i) == '1')
{
counter++;
remaining = remaining + d1.charAt(i);
}
else
{
remaining = remaining + d1.charAt(i);
counter = 0;
}
if(counter == 5)
{
remaining = remaining + '0';
counter = 0;
}
}
System.out.println("Flag--> 01111110");
String new1="|01111110 | "+remaining+" | 01111110|";
System.out.println("Stuffed data at intermediate site is:");
for(int k=0;k<=(28+d1.length());k++)
{
System.out.print("-");
}
System.out.println();
System.out.println(" "+new1);
for(int k=0;k<=(28+d1.length());k++)
{
System.out.print("-");
}
System.out.println();
counter=0;
for(int i=0;i<remaining.length();i++)
{
if(remaining.charAt(i) == '1')
{
counter++;
output = output + remaining.charAt(i);
}
else
{
output = output + remaining.charAt(i);
counter = 0;
}
if(counter == 5)
{
if((i+2)!=remaining.length())
{
output = output + remaining.charAt(i+2);
}
else
{
output=output + '1';
}
i=i+2;
counter = 1;
}
}
System.out.println("Destuffed BIT is: "+output);
}
}
Character Stuffing and Destuffing

import java.io.*;
import java.util.*;
import java.lang.*;
class Charstuff
{
public static void main(String args[])
{
Scanner k =new Scanner (System.in);
System.out.println("enter the string\t");
String s=k.nextLine();
String str1;
String str2="";
int i,m,j;
m=s.length();
System.out.println("original data "+s);
str1="dlestx";
for(i=0;i<=m-1;i++)
{
if((s.charAt(i)=='d')&&(s.charAt(i+1)=='l')&&(s.charAt(i+2)=='e'))
{
str1=str1+"dle";
}
str1=str1+s.substring(i,i+1);
}
str1=str1+"dleetx";
int p=str1.length();
System.out.println("transmitted data "+str1);
for(i=6;i<p-6;i++)
{

if((str1.charAt(i)=='d')&&(str1.charAt(i+1)=='l')&&(str1.charAt(i+2)=='e')&&(
str1.charAt(i+3)=='d')&&(str1.charAt(i+4)=='l')&&(str1.charAt(i+5)=='e'))
{
i=i+3;
}
str2=str2+str1.substring(i,i+1);
}
System.out.println("received data is "+str2);
}
}

You might also like