/*利用的是java下,一个字符占两个字节,unicode码也是两个字节*/
public String strtoerjz(String str){//从字符串str转换到其unicode码下二进制表示的字符串erjz
short temp;
byte shiliu=15;
String erjz="";
for(int i=0;i<str.length();i++){
temp=(short)str.charAt(i);
while(shiliu>=0){
if(Math.pow(2,shiliu)<temp){
erjz+='1';
temp-=Math.pow(2, shiliu);
shiliu--;
}
else if(Math.pow(2, shiliu)>temp){
erjz+='0';
shiliu--;
}
else{
erjz+='1';
shiliu--;
while(shiliu>0){
erjz+='0';
shiliu--;
}
}
}
shiliu=15;
}
return erjz;
}
public String erjztostr(byte[] byt){//byt数组保存的是0或1的字符串unicode码,byt[0]=1/0.....返回str其对应的unicode码下的值
String str="";short temp=0;
for(int i=0,num=0;i<byt.length;i++){
temp+=Math.pow(2,15-i+num)*byt[i];
if((i+1)%16==0){
str+=(char)temp;
temp=0;
num+=16;
}
}
return str;
}
public String erjztostR(String str){//str是0或1的字符串的unicode码,返回endstr是其对应的unicode码下的值
String endstr="";short temp=0;
for(int i=0;i<str.length();i++){
temp+=Math.pow(2,15-i+num)*(str.charAt(i)-'0');
if(i+1)%16==0){
endstr+=(char)temp;
temp=0;
num+=16;
}
}
return endstr;
}