【散分贴】一道运算符的JAVA题,求解析
int a=-67,b=116,c=78;
int d=~a|b&c;
System.out.println(d);
请高手们 详细指导指导一下,本人基础差一点
------解决方案--------------------d是70
------解决方案--------------------位运算啊。这样就看清楚了:
(整数32位,~是按位取反,&是按位与,|是按位或)
int a=-67,b=116,c=78;
int d=~a|b&c;
System.out.println(Integer.toBinaryString(a));
System.out.println("0000000000000000000000000" + Integer.toBinaryString(~a));
System.out.println("0000000000000000000000000" + Integer.toBinaryString(b));
System.out.println("0000000000000000000000000" + Integer.toBinaryString(c));
System.out.println("0000000000000000000000000" + Integer.toBinaryString(b&c));
System.out.println("0000000000000000000000000" + Integer.toBinaryString(d));
System.out.println(d);
------解决方案---------------------67:111...1011 1101
116:000...0111 0100
78: 000...0100 1110
116&78: 000...0100 0100
~67: 000...0100 0010
|: 000...0100 0110
所以结果是70,我dt了,竟然真的自己算了遍
------解决方案--------------------位运算啦