Easy to understand C++ solution using vector

interview-questions
amazon
Tags: #<Tag:0x00007f2428d3af10> #<Tag:0x00007f2428d3add0>

#1
unsigned int Solution::reverse(unsigned int A) 
{
    unsigned int s=0;
    int i,j=31;
    vector <int> B;
    //Converting decimal to Binary
    while(A>0)
    {
        B.push_back(A%2);
        A/=2;
    }

    //Finding the decimal value corresponding to the 32 bit binary
    for(i=0;i<B.size();i++)
    {
        s+=B[i]*pow(2,j);
        j--;
    }
    return(s);
}