To implement Bit Stuffing > Java Program

To implement Bit Stuffing > Java Program

Computer Networks


import java.io.*;

public class BitStuffing {
   

  public static void main(String[] args)throws IOException {
   int i=0,x,q=0;
   InputStreamReader isr = new InputStreamReader(System.in);
   BufferedReader br = new BufferedReader(isr);
   String sy="01111110",sx;
   StringBuilder sby = new StringBuilder(sy);
   System.out.print("ENTER THE DATA: ");
     sx = br.readLine();
     StringBuilder sbx = new StringBuilder(sx);
     x = sx.length();
      while(i+5<=x){
           String s1 = sx.substring(i, i+5);
           if(check(s1)){
               sbx.insert(i+5,0);
                i=i+6;
           }
           else i++;
       }    
     
      System.out.print("BIT STUFFING: ");  
      System.out.println(sbx);
      System.out.print("FINAL OUTPUT: ");
      System.out.println(sby+"  "+sbx+"  "+sby);
      System.out.println(sby.append(sbx.append(sby)));
    
  }
  private static boolean check(String s){
      String s1 = "11111";
      if(s.equals(s1))
          return true;
      else return false;      
   }
  
    
}


OUTPUT:
run:
ENTER THE DATA: 110011111101111111
BIT STUFFING: 11001111101011110111
FINAL OUTPUT: 01111110  11001111101011110111  01111110
011111101100111110101111011101111110
BUILD SUCCESSFUL (total time: 19 seconds)

Comments

Popular posts from this blog

Intermediate Code Generation > C Program