将72位转化成字符串1、首先将72位转为9个字节,然后9个字节用16进行表示,再将16进制表示的9个字节原样转为String(18个字符)
2、“位”用哪种类型存储比较好啊。
两个问题 请大家帮帮我!
2、“位”用哪种类型存储比较好啊。
两个问题 请大家帮帮我!
解决方案 »
- csdn下载页面的资源怎么不见下载按钮或链接啊?
- 请教关于循环求最优解的问题!
- 想问下系统集成项目管理工程师是做什么的?
- 关于Hibernate的问题
- 各位大师,帮忙解决几个java问题!感激不尽.
- 论坛上发帖的时间和系统的时间差八小时
- Throwable 是否经常使用
- 求助 搞不懂为何tomcat前两天可以用现在用不了了
- 【UNIX】【中软同和】【SCOUNIX培训录像】
- The function equals must be used with a prefix when a default namespace is n
- j2ee项目上传到空间上遇到的问题,请高手进来帮忙!
- 在struts2中redirect的具体作用是什么
9个字节转换为4.5个字符 (unicode一个字符两个字节)!
9个字节当然转成18字符了 我的意思是这样的 比如 11111111->0xFF->"FF" 反正String.length是18的请问怎么弄
不是ACS码形式的转化 是原样转化
//72位,72个0、1字符
String s="11111111,11111111,11111111,11111111,111111111,11111111,111111111,11111111,11111111";
//9个字节
String[] ss=s.split(",");
byte[] bs=new byte[9];
for(int i=0;i<bs.length;i++){
bs[i]=Byte.parseByte("01111111",2);
//18个字符
System.out.println(Integer.toHexString(bs[i]));
}
}
//可以格式化后再输出
Integer.toHexString(bs[i])
String encoding = "gb2312";
ByteToCharConverter bcConverter = ByteToCharConverter.getConverter(encoding);
String str = "1001000,1100101,1101100,1101100,1101111,0100000,1010111,1101111,1110010,1101100,1100100,0100001"; String[] ss = str.split(","); byte[] bytes = new byte[ss.length];
for (int i = 0; i < ss.length; i++) {
bytes[i] = Byte.parseByte(ss[i], 2);
// 18个字符
System.out.println("bytes[" + i + "]= 10进制:" + bytes[i] + " - 16进制:" + Integer.toHexString(bytes[i]));
} char[] chars = bcConverter.convertAll(bytes);
for (int i = 0; i < chars.length; i++) {
System.out.println("chars[" + i + "]=" + chars[i]);
}
String s = new String(chars);
System.out.println("字符串:" + s);
}
输出:
bytes[0]= 10进制:72 - 16进制:48
bytes[1]= 10进制:101 - 16进制:65
bytes[2]= 10进制:108 - 16进制:6c
bytes[3]= 10进制:108 - 16进制:6c
bytes[4]= 10进制:111 - 16进制:6f
bytes[5]= 10进制:32 - 16进制:20
bytes[6]= 10进制:87 - 16进制:57
bytes[7]= 10进制:111 - 16进制:6f
bytes[8]= 10进制:114 - 16进制:72
bytes[9]= 10进制:108 - 16进制:6c
bytes[10]= 10进制:100 - 16进制:64
bytes[11]= 10进制:33 - 16进制:21
chars[0]=H
chars[1]=e
chars[2]=l
chars[3]=l
chars[4]=o
chars[5]=
chars[6]=W
chars[7]=o
chars[8]=r
chars[9]=l
chars[10]=d
chars[11]=!
字符串:Hello World!