C++ 3 line easy to understand solution


#1
unsigned int reverse(unsigned int A) {

    unsigned int B=0;
    while(A>0){
          int p = log2(A & -A) + 1; // find position of lowest right set bit
          B |= (1<<(32-p)); //set 32-p position bit
          A &= (A-1); // unset rightmost set bit
     }
    return B;

}