日期:2014-05-20  浏览次数:20644 次

关于位运算
int t=0;
t=~t;
请问为什么t会是-1;


Given an array of integers, every element appears three times except for one. Find that single one.

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
 public int singleNumber(int[] A) {  
        int once = 0;  
        int twice = 0;  
  
  
        for (int i = 0; i < A.length; i++) {  
            twice |= once & A[i];  
            once ^= A[i];  
            int not_three = ~(once & twice);  
            once = not_three & once;  
            twice = not_three & twice;  
        }  
        return once;  
    }  
这段代码怎么理解,求指导。 位运算学的好烂。。
位运算

------解决方案--------------------
int 0 二进制表示形式:0000 0000 0000 0000 0000 0000 0000 0000
各位全部取反:1111 1111 1111 1111 1111 1111 1111 1111

 -1 的二进制补码表示为:1111 1111 1111 1111 1111 1111 1111 1111