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;
}
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;
}
相关文章推荐
- JAVA_SE基础——19.数组的定义
- JAVA接口笔记
- spring aop学习笔记
- 02_java关键字、表识符、注释、进制转换、补码反码、数据类型转换
- java基础知识—Java中的反射机制
- Java Exception和Error的区别
- Java实训项目--影碟管理软件
- Java week1
- 【java设计模式】中介者模式
- springMVC对异常处理的支持
- Struts2之如何使用简单的UI标签
- java语言复制二进制流数据
- springmvc解析器使用总结
- java分派
- Java应用程序利用Exe4j打包exe文件
- Java代码查看所有的系统属性
- Java锁的可重入性(Reentrancy)
- flex与JAVA的SOCKET通信
- 使用IntelliJ IDEA 14和Maven创建java web项目
- 环境变量的解释和配置 以及命令行运行java程序