Java整数到字节数组我得到一个整数: 1695609641当我使用方法时:String hex = Integer.toHexString(1695609641);system.out.println(hex);得到:6510f329但我想要一个字节数组:byte[] bytearray = new byte[] { (byte) 0x65, (byte)0x10, (byte)0xf3, (byte)0x29};我该怎么做?
3 回答

神不在的星期二
TA贡献1963条经验 获得超6个赞
使用Java NIO的ByteBuffer非常简单:
byte[] bytes = ByteBuffer.allocate(4).putInt(1695609641).array();for (byte b : bytes) { System.out.format("0x%x ", b);}
输出:
0x65 0x10 0xf3 0x29
添加回答
举报
0/150
提交
取消