您的位置:首页 > 编程语言 > Java开发

java int to byte array

2015-07-19 17:04 489 查看
引用 http://anjun.cc/post/651.html

private byte[] intToByteArray(final int integer) throws IOException {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// DataOutputStream dos = new DataOutputStream(bos);
// dos.writeInt(integer);
// dos.flush();
// return bos.toByteArray();
byte[] result = new byte[4];

result[0] = (byte) (integer >> 24 & 0xff);
result[1] = (byte) (integer >> 16 & 0xff);
result[2] = (byte) (integer >> 8 & 0xff);
result[3] = (byte) (integer & 0xff);

return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: