Why the size is 4294967295 not 0


  • 0
    S

    I try to use stack to revert bit , first while loop is put every bit in stack
    suppose to exit the loop when size == 0 , but it become 4294967295
    Does anybody know why ?

    uint32_t reverseBits(uint32_t n) {
        stack<bool> s;
        uint32_t size = 32;
        uint32_t ret = 0;
        while(size-- > 0){
            
            if(n & 1) {
              cout << "1 " << size  << endl;
              s.push(true);  
            } else {
              cout << "0 " << size << endl;
              s.push(false);
            }
            n = n >> 1;
        }
        // size here suppose to be 0 , but it is 4294967295
        cout << size << endl;
        while(!s.empty()){
            if(s.top()){
                cout << "1 " << size << endl;
                ret |= (1<<size);
            } else {
                cout << "0 " << size << endl;
            }
            size++;
            s.pop();
        }
        return ret;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.