public static byte[] toByteClass(String msg){
byte[] bt= new byte[2];
int res = Integer.parseInt(msg);
int num = Integer.parseInt(Integer.toHexString(res));
bt[0] = (byte) ((res >> 8) & 0xff);// 次低位
bt[1] = (byte) (res & 0xff);// 最低位
// bt[2] = (byte) ((res >> 16) & 0xff);// 次高位
// bt[3] = (byte) (res >>> 24);// 最高位,无符号右移。
return bt;
}java中将int型数据转换成byte字节数组
最新推荐文章于 2024-08-15 02:15:24 发布
本文介绍了一种将字符串转换为固定长度字节数组的方法。该方法使用 Java 编写,通过 Integer 类的静态方法实现字符串到整数的转换,并进一步将整数拆分为多个字节。此技术适用于需要进行数据类型转换的场景。
1346

被折叠的 条评论
为什么被折叠?



