你永远不知道客户的想法有多奇葩、
10进制 转换 16进制
byte[] test = new byte[4];
test[0] = (byte)0x36;//写死的数据,放上去多少就是多少,不会改变
test[1] = (byte)36; //系统自动转为16进制 即 24
test[2] = (byte) Integer.parseInt("36").getBytes(); //同上
test[3] = (byte)intTointByte(36)'; // 也是会被强制转成byte只不过是提前补了 10位转16位的数 ,即
intTointByte(36) = 3*16+6 = 54
最后的结果:test[0] = 24
test[1] = 24
test[2] = 24
test[3] = 36
代码效果即是: int 36 = byte 36
public static int intTointByte(int args) { int hex_all = 0; if (args>10){ int ten_num = Integer.parseInt((args+"").substring(0,1)); int hex_1 = ten_num*16; int hex_2 = Integer.parseInt((args+"").substring(1,2)); hex_all = hex_1+hex_2; }else { hex_all = args; } Log.e("hex_all",hex_all+""); return hex_all; }