What is wrong in my logic? can anyone point out?


#1

unsigned int arr[32];

for(int i=0;i<32;i++){
    arr[i]=(A & 1);
    A=A>>1;
}
unsigned int deci=0;
int p=32;
for(int i=0;i<32;i++){
    deci+= arr[i]* pow(2,p);
    p--;
}
return deci;

Blockquote


#2

p must be 31
since 32 bit meanse 2^0 , 2^1 , 2^2…2^31.