当前位置: 技术问答>java相关
怎样将一个能int值转变为四个byte?(big endian)请提供代码实例,谢谢!
来源: 互联网 发布时间:2015-01-04
本文导语: 怎样将一个能int值转变为四个byte?(big endian)请提供代码实例,谢谢! | BigInteger.toByteArray()可以吗 | int i = 0x12345678; byte[] b = new byte[4]; b[0] = new Integer(i & 0x000000FF).by...
怎样将一个能int值转变为四个byte?(big endian)请提供代码实例,谢谢!
|
BigInteger.toByteArray()可以吗
|
int i = 0x12345678;
byte[] b = new byte[4];
b[0] = new Integer(i & 0x000000FF).byteValue();
b[1] = new Integer((i & 0x0000FF00) >>> 8).byteValue();
b[2] = new Integer((i & 0x000000FF) >>> 16).byteValue();
b[3] = new Integer((i & 0x000000FF) >>> 24).byteValue();
Anyway, hope this will be of use.
byte[] b = new byte[4];
b[0] = new Integer(i & 0x000000FF).byteValue();
b[1] = new Integer((i & 0x0000FF00) >>> 8).byteValue();
b[2] = new Integer((i & 0x000000FF) >>> 16).byteValue();
b[3] = new Integer((i & 0x000000FF) >>> 24).byteValue();
Anyway, hope this will be of use.