simpe c solution


  • -1
    B

    This is nothing but swaping of bits....
    31-0(swap)
    30-1(swap)
    29-2(swap)
    .
    .
    .
    .
    16-15(swap)
    uint32_t reverseBits(uint32_t n) {
    int i=0,j=31,x=1,y=1,x1,y1;
    for(i=0,j=31;i<j;){
    x=1<<i;
    y=1<<j;
    x1=x&n;
    y1=y&n;
    if((!x1&&y1)){
    n|=x;
    n^=y;
    }
    else if((x1&&!y1)){
    n|=y;
    n^=x;
    }
    i++;
    j--;

    }
    return n;

    }


Log in to reply
 

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