与(&),或(|),非(~),异或(^),左移(<<),右移(>>)运算符的组合计算
/*** 【对正数进行非运算】:得出补码,-1取反的反码,反码取反码得非运算的原码* ~7:(7取反值后高位为1,所以转码后的值为源码的绝对值-1,此时再取反值即为7的反值)* 00000111(0正1负) -> 01111000(补码) - 1 = 01110111(反码) -> 10001000(原码) = -8**/System.out.println(~7);/*** 【对负数进行非运算:得出补码,+1后取反码的反码即为非运算的原码】* ~-7: (将补码计算出原码然后转化为十进制,高位不变,取反+1)* 10000111(-7) -> 11111000(补码) + 1 = 11111001(反码) -> 00000110(原码) = 6**/System.out.println(~-7);/*** 3:00000011 2:00000010 1:00000001* 3/2 = 1 ; 4/2 = 2 ; 3/1 = 3* 1&2:(相同为1,否则为0)* 00000001* 00000010* --------------* 00000000 : 0(十进制)* 0|3:(有一个为1则为1,否则为0)* 00000000* 00000011* --------------* 00000011 : 3(十进制)**/System.out.println(3/2&4/2|3/1);/*** 4&~7(与非运算) = 0 3^0(异或运算) = 3* 4:00000100 7:00000111 3:00000011* ~7:00000111(0正1负) -> 01111000(补码) - 1 = 01110111(反码) -> 10001000(原码) = -8* 4&~7:* 00000100* 10001000* ------------* 00000000 : 0(十进制)* 3^0:(相同为0,否则为1)* 00000011* 00000000* ------------* 00000011 : 3(十进制)***/System.out.println(3^4&~7);/*** 4:00000100 将1右移两位 ==> 00000001:1*2^0 = 1*1 = 1**/System.out.println(4>>2);/*** 4:00000100 将1左移3位 ==> 00100000:1*2^5 = 1*32 = 32**/System.out.println(4<<3);