java中int、long与byte数组相互转换
来源:互联网 发布:gps数据导入谷歌地球 编辑:程序博客网 时间:2024/05/16 09:46
1、int转换成4个byte数组
public static byte[] intToByteArray2(int a) { return new byte[] { (byte) ((a >> 24) & 0xFF), (byte) ((a >> 16) & 0xFF), (byte) ((a >> 8) & 0xFF), (byte) (a & 0xFF) }; }
2、4个byte数组转成int
public static int byteArrayToInt2(byte[] b) { return b[3] & 0xFF | (b[2] & 0xFF) << 8 | (b[1] & 0xFF) << 16 | (b[0] & 0xFF) << 24; }
3、long转成8个字节数组
public static byte[] longToBytes(long x){ ByteBuffer bb = ByteBuffer.allocate(8); bb.putLong(0, x); return bb.array(); }
public static long byteArrayTolong(byte[] b){ ByteBuffer bb = ByteBuffer.allocate(8); bb.put(b, 0, b.length); bb.flip(); return bb.getLong(); }
0 0
- java中int、long与byte数组相互转换
- java byte数组与int,long,short,byte转换
- java byte数组与int,long,short,byte转换
- Java中byte数组与long数组相互转化
- Java中byte数组与long数组相互转化
- java中byte数组与int,long,short间的转换
- java中long,int,short与byte数组之间的转换
- java中long,int,short与byte数组之间的转换
- java中byte数组与int,long,short,float,char之间的转换
- java中byte数组与int,long,short间的转换 .
- java中byte数组与int,long,short间的转换
- java中byte数组与int,long,short,float,char之间的转换
- java中byte数组与int,long,short间的转换
- java中long,int,short与byte数组之间的转换
- Java中byte数组与short,int,char,long,float,double之间的转换
- java中byte数组与int,long,short间的转换 (以备查阅)
- java中byte数组与int,long,short间的转换
- java中long,int,short与byte数组之间的转换
- [学习笔记] - Ubuntu 下安装MongoDB
- svn: Commit blocked by pre-commit hook (exit code 255) with output:报错分析及解决方法
- Set与List之间转化
- 电信自注册基础知识
- VS2010 常用快捷键
- java中int、long与byte数组相互转换
- Android系统启动流程三之android
- 软件项目周期管理
- getLocationInWindow getLocationOnScreen 获取Android坐标
- 概述 Bean Validation 规范
- HDU 5895 欧拉定理+快速幂+公式
- 软件测试——透过表象看本质
- 线程睡眠(sleep)线程让步(yield)
- tomcat 标准目录及手工部署app