java怎么讲二进制转换为字符串

如题所述

第1个回答  2016-08-10
public static String getSecret(byte[] b){//得到密文
String string="";
int c=b.length/6;
int last=b.length%6;
int point=0;
int temp=0;
for(int i=0;i<c;i++){
for(int j=6;j>0;j--){
int temp1=Integer.valueOf(b[point])-48;
int z=0;
while(z<j-1){
temp1=temp1*2;
z++;
}
point++;
temp=temp+temp1;
}
String string2=String.valueOf((char)temp);
string=string+string2;
temp=0;
}
for(;last>0;last--){
int z=0;
int temp1=Integer.valueOf(b[point])-48;
while(z<last-1){
temp1=temp1*2;
z++;
}
point++;
temp=temp+temp1;
}
String string2=String.valueOf((char)temp);
string=string+string2;
return string;
}本回答被提问者采纳