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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ilyzj/article/details/7998734

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

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;
}


 

展开阅读全文

没有更多推荐了,返回首页