Java 位运算 64位long数据 转成2个 32位 int数据 及 回加成原数据

義往昔 1月前 ⋅ 67 阅读

在java中long数据类型长度为64bit,而int是32bit.所以刚好可以换成2个

高4 :  4字节*8=32

低4: 4字节*8=32

public List<Integer> changLong(long num) {
int intNum1 = (int) num;
int intNum2 = (int) (num >> 32);

List<Integer> list = new ArrayList<Integer>();
list.add(intNum1);
list.add(intNum2);
return list;
}

public long getLongFromInt(int num1, int num2) {
// long l1 = (long)(((long)num2&0xffffffff)<<32);
// long l2 = (long)num1&0x00000000ffffffffL;
// 简写
long l1 = (num2 & 0x00000000ffffffffL) << 32;
long l2 = num1 & 0x00000000ffffffffL;

long num = l1 | l2;
return num;
}

https://blog.csdn.net/ilyzj/article/details/7998734

 

 


全部评论: 0

    我有话说: