You are viewing a single comment's thread. Return to all comments →
long flippingBits(long n) { int binary_array[32]; int count=0; int index=31; while(count<32){ binary_array[index--]=n%2; n=n/2; count++; }
for(int i=0;i<32;i++){ if(binary_array[i]==0){ binary_array[i]=1; } else{ binary_array[i]=0; } } long flipResult=0; int power=0; for(int i=31;i>=0;i--){ flipResult+=binary_array[i]*pow(2, power++); } return flipResult;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping bits
You are viewing a single comment's thread. Return to all comments →
long flippingBits(long n) { int binary_array[32]; int count=0; int index=31; while(count<32){ binary_array[index--]=n%2; n=n/2; count++; }
}