首页 > 代码库 > 待解:一元非运算符

待解:一元非运算符

 1 // Demonstrate the bitwise NOT. 2 class NotDemo { 3     public static void main(String[] args) { 4         byte b = -34; 5          6         for(int t = 128; t > 0; t = t/2) { 7             if((b & t) != 0) System.out.print("1 "); 8             else System.out.print("0 "); 9         }10         System.out.println();11         12         // reverse all bits13         b = (byte) ~b;14         15         for(int t = 128; t > 0; t = t/2) {16             if((b & t) != 0) System.out.print("1 ");17             else System.out.print("0 ");18         }19     }20 }

执行结果:

1 1 0 1 1 1 1 0
0 0 1 0 0 0 0 1

待解:一元非运算符