array = System.Text.Encoding.ASCII.GetBytes(hx);
return array;
}
(2)Java 代码
/**
* 10进制数转化为定长度的16进制字节数组
*
* @param value
* 值
* @param len
* 长度限制
* @return
*/
public final byte[] intToHexBytes(int value, int len) {
String s = Integer.toHexString(value);
len = len - s.length();
for (int i = 0; i < len; i++) {
s = "0" + s;
}
return s.getBytes();
2.7 协议报示例
-117,-82,-101,48,48,48,48,51,54,48,48,48,48,48,49,54,85,61,110,117,108,108,78,89,97,110,103,71,117,111,77,105,110,44,38,84,61,50,48,49,48,45,48,53,45,48,53,32,49,51,58,49,52,58,53,49,38,83,61,121,103,109,49,38,82,61,121,103,109,50,60,63,120,109,108,62,32,46,46,46,32,46,46,46,32,32,60,47,120,109,108,62
| 字节码
| 数值
| 描述
|
| 16进制
| 10进制
|
3 字节
| 139,174,155
(或-117,-82,-101)
| ®
| 0x8b, 0xae, 0x9b
| 报文开始标记
|
139, 174, 155
|
2 字节
| 48,48
| 00
| 0
| 0
| 报文类型
|
4 字节
| 48,48,51,54
| 0036
| 36
| 54
| 报头长度
|
7 字节
| 48,48,48,48,48,49,54
| 0000016
| 16
| 22
| 正文长度
|
54字节
| 85,61,110,117,108,108,
78,89,97,110,103,71,
117,111,77,105,110,44,
38,84,61,50,48,49,
48,45,48,53,45,48,
53,32,49,51,58,49,
52,58,53,49,38,83,
61,121,103,109,49,38,
82,61,121,103,109,50
| 发送者: ygm1
接收者: ygm2
发送时间: 2010-05-05 13:14:51
… …
| 报头
|
22字节
| 60,63,120,109,
108,62,32,46,46,46,
32,46,46,46,32,32,
60,47,120,109,108,62
| <?xml> ... ...
| 正文
|