逝者如斯夫

静而思之
数据加载中……

复合常量的问题

可以使用一个变量或字段记录几个复合状态:



int a = 1;
System.out.println(a);
System.out.println(
"Integer.toBinaryString(a)=" +
Integer.toBinaryString(a));
System.out.println(
"Integer.toHexString(a)=" + Integer.toHexString(a));
System.out.println(
"Integer.toOctalString(a)=" +
Integer.toOctalString(a));
= 2;
System.out.println(a);
System.out.println(
"Integer.toBinaryString(a)=" +
Integer.toBinaryString(a));
System.out.println(
"Integer.toHexString(a)=" + Integer.toHexString(a));
System.out.println(
"Integer.toOctalString(a)=" +
Integer.toOctalString(a));

= 4;
System.out.println(a);
System.out.println(
"Integer.toBinaryString(a)=" +
Integer.toBinaryString(a));
System.out.println(
"Integer.toHexString(a)=" + Integer.toHexString(a));
System.out.println(
"Integer.toOctalString(a)=" +
Integer.toOctalString(a));

= 8;
System.out.println(a);
System.out.println(
"Integer.toBinaryString(a)=" +
Integer.toBinaryString(a));
System.out.println(
"Integer.toHexString(a)=" + Integer.toHexString(a));
System.out.println(
"Integer.toOctalString(a)=" +
Integer.toOctalString(a));

int b = 1 | 2 | 4 | 8;
System.out.println(
"1 | 2 | 4 | 8 = " + b);

int b1 = 4;
System.out.println(b1 
+ " is In " + b + " ? " + ((b1 & b) == b1) );



posted on 2007-04-20 10:26 ideame 阅读(856) 评论(0)  编辑  收藏 所属分类: Java


只有注册用户登录后才能发表评论。


网站导航: