Google Search

Friday, October 7, 2011

write a bit count program in java


BITS


import java.io.*;
class bits{
String sender(String s){
String s1="";
char c;
int i=0,count=0;
for(i=8;i<s.length()-8;i++)
{
if(s.charAt(i)=='0')
{
count=0;
s1=s1+"0";
}
else{
count++;
s1=s1+"1";
if(count==5){
count=0;
s1=s1+"0";
}
}
}
System.out.println("the inf sended is"+s1);
return s1;
}






void receiver(String s1){
int i,count;
String s2="";
count=0;
for(i=0;i<s1.length();i++){
if(s1.charAt(i)=='0'){
s2=s2+"0";
count=0;
}
else{
s2=s2+1;
count++;
if(count==5){
count=0;
i++;
}
}
}
System.out.println("received string"+s2);
}




public static void main(String ar[]){
String s=" ";
for(int i=0;i<ar.length;i++)
s=ar[i];
s="01111110"+s+"01111110";


bits b=new bits( );
System.out.println("s value in main"+s);
s=b.sender(s);
//System.out.println("s value in main"+s);
b.receiver(s);


}
}

0 comments:

Post a Comment