请问如何把LONG型赋值给2个INT型? int a,b;float c;如何把8个字节的Long转成2个4个字节的int保存呢?请详细说明..谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 long a;int b,c;c = (int)a ;得到a的后4个字节b = a>>32 ; 向右移动32位,得到前4个字节 public class test1 { public static void main(String[] args) { long a=21115111111L; int x=-1; //打印a的二进制表示 for(int i = 63; i >= 0; i--){ if(((1L << i) & a) != 0) System.out.print("1"); else System.out.print("0"); } System.out.println(); int b,c; b=(int) (a&x); c=(int)((a>>32)&x); ////打印c的二进制表示 for(int j = 31; j >= 0; j--) if(((1 << j) & c) != 0) System.out.print("1"); else System.out.print("0"); System.out.println();//打印b的二进制表示 for(int j = 31; j >= 0; j--) if(((1 << j) & b) != 0) System.out.print("1"); else System.out.print("0"); System.out.println(); System.out.println(b); System.out.println(c); } } 00000000000000000000000000000100111010101000111100000110110001110000000000000000000000000000010011101010100011110000011011000111-3597253694 楼上的方法肯定不行关注ing 运行出现Exception in thread "main" java.lang.StackOverflowError 怎么解决 推荐一本关于数据结构java语言描述的好书。 请问下列代码编译和执行没有错误的是? EJB3.0 实体主键 有关于抽象类的一个问题! Rmi客户端异常,达人们出来指教一二(急) java数据库连接问题 求助JAVA数据库问题 求一个算法的思路 JB6的设置问题!帮忙呀~~ 急,在线等待。100 分求java日期时间格式问题 关于异常方法!
int b,c;
c = (int)a ;得到a的后4个字节
b = a>>32 ; 向右移动32位,得到前4个字节
public static void main(String[] args) {
long a=21115111111L;
int x=-1;
//打印a的二进制表示
for(int i = 63; i >= 0; i--){
if(((1L << i) & a) != 0)
System.out.print("1");
else
System.out.print("0");
}
System.out.println();
int b,c;
b=(int) (a&x);
c=(int)((a>>32)&x);
////打印c的二进制表示
for(int j = 31; j >= 0; j--)
if(((1 << j) & c) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
//打印b的二进制表示
for(int j = 31; j >= 0; j--)
if(((1 << j) & b) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
System.out.println(b);
System.out.println(c);
}
} 0000000000000000000000000000010011101010100011110000011011000111
00000000000000000000000000000100
11101010100011110000011011000111
-359725369
4
关注ing