Follow me on Linkedin

Implementing data link layer framing method bit stuffing in java Program

         Implementing data link layer framing method bit stuffing in java Program

import java.io.*;
public class aslamjai
{
public static void main(String args[]) throws IOException
{
int temp;
int data[]=new int[8];
int flag[]=new int[5];

int fdata[]=new int[25];
int fidata[]=new int[25];

DataInputStream obj= new DataInputStream(System.in);
System.out.println("Enter the Data Bits.....");

for (int i=0;i<8;i++)
{
data[i] = Integer.parseInt(obj.readLine());
}
System.out.println("Enter Flag Bits.....");

for (int i=0;i<5;i++)
{
flag[i] = Integer.parseInt(obj.readLine());
}
int idx=0;
for (int i=0;i<5;i++)
{
fdata[idx++] = flag[i];
}
for (int i=0;i<8;i++)
{
fdata[idx++] = data[i];
}

for (int i=0;i<5;i++)
{
fdata[idx++] = flag[i];
}
int fidx=0,count=0;
for(int i=0;i<idx;i++)
{
fidata[fidx++]=fdata[i];

if(fdata[i]==1)
count++;
else
count=0;
if(count==5)
{
fidata[fidx++]=0;
count=0;
}
}
System.out.print("Stuff Data : ");
for(int i=0;i<fidx;i++)
{
System.out.print(fidata[i]);
}

int k;
int mycount=0;
int mysecondcount=0;
int  mydata[]=new int[25];
for(k=0;k<fidx;k++)
{
mydata[mysecondcount++]=fidata[k];

if(fidata[k]==1)
mycount++;
else
mycount=0;

if(mycount==5)
{
mycount=0;
k++;
}
}
int j=mysecondcount;
System.out.println(" ");
System.out.print("Inverse : ");
for(int g=0;g<j;g++)
{
System.out.print(mydata[g]);
}
}
}



0 comments:

Post a Comment

a