java socket 如何发送16进制数据 java socket 如何发送16进制数据 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 发送消息之前转码为16进制 public static final String encodeHex(String msg) { byte[] bytes = null; try { bytes = msg.getBytes("GBK"); } catch (java.io.UnsupportedEncodingException e) { e.printStackTrace(); } StringBuffer buff = new StringBuffer(bytes.length * 4); String b; char a; int n = 0; int m = 0; for (int i = 0; i < bytes.length; i++) { b = Integer.toHexString(bytes[i]); if (bytes[i] > 0) { buff.append("00"); buff.append(b); n = n + 1; } else { a = msg.charAt((i - n) / 2 + n); m = a; b = Integer.toHexString(m); buff.append(b.substring(0, 4)); i = i + 1; } } return buff.toString(); } public static final String encodeHex(String msg) { byte[] bytes = null; try { bytes = msg.getBytes("GBK"); } catch (java.io.UnsupportedEncodingException e) { e.printStackTrace(); } StringBuffer buff = new StringBuffer(bytes.length * 4); String b; char a; int n = 0; int m = 0; for (int i = 0; i < bytes.length; i++) { b = Integer.toHexString(bytes[i]); if (bytes[i] > 0) { buff.append("00"); buff.append(b); n = n + 1; } else { a = msg.charAt((i - n) / 2 + n); m = a; b = Integer.toHexString(m); buff.append(b.substring(0, 4)); i = i + 1; } } return buff.toString(); } 求解!!! 写聊天室时遇到的问题,时间比较短,请大家帮忙~~~~ 如何通过菜单项切换到某个dialog? 这个问题求人帮忙 谢谢 如何才能显示中文 很简单的问题 请问部署和数据结构是什么意思呢? 请问如何在java中执行sql块语句? 为什么有的java applet在网页中运行不了! 用getInstance 和 new 创建对象有什么区别吗? Java socket编程的一些问题 jsp 出现中文输入乱码 请教各位 另外再问一下hibernate 连接mysql 驱动写法 jsf inputText disable=true后滚动条不可用
byte[] bytes = null;
try {
bytes = msg.getBytes("GBK");
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
}
StringBuffer buff = new StringBuffer(bytes.length * 4);
String b;
char a;
int n = 0;
int m = 0;
for (int i = 0; i < bytes.length; i++) {
b = Integer.toHexString(bytes[i]);
if (bytes[i] > 0) {
buff.append("00");
buff.append(b);
n = n + 1;
} else {
a = msg.charAt((i - n) / 2 + n);
m = a;
b = Integer.toHexString(m);
buff.append(b.substring(0, 4)); i = i + 1;
}
}
return buff.toString();
}
byte[] bytes = null;
try {
bytes = msg.getBytes("GBK");
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
}
StringBuffer buff = new StringBuffer(bytes.length * 4);
String b;
char a;
int n = 0;
int m = 0;
for (int i = 0; i < bytes.length; i++) {
b = Integer.toHexString(bytes[i]);
if (bytes[i] > 0) {
buff.append("00");
buff.append(b);
n = n + 1;
} else {
a = msg.charAt((i - n) / 2 + n);
m = a;
b = Integer.toHexString(m);
buff.append(b.substring(0, 4)); i = i + 1;
}
}
return buff.toString();
}