/* * Node if a number if power of two, it will have only 1 bit whose value will be 1 * On that number if we do n-1, it will flip all the bits, & operation on that * will lead to zero */ int main (int argc, char *argv[]) { int num = 0; int a, b; printf("Enter a number to check if its power of two:"); scanf("%d",&num); printf("\n"); if((num & (num-1)) == 0) { printf("its a power of two\n"); } else { printf("its not a power of two\n"); } printf("swapped Odd Even bits : %d\n",swapOddEvenBits(num)); printf("Find number bit flip required to make two numbers equal: Enter two number:"); scanf("%d",&a); printf("\n"); scanf("%d",&b); printf("\nNum of bit flips needed to make them equal %d\n",bitSwapRequired(a,b)); for (int i=0;i< 32;i++){ bin(i); printf("\n"); } }
int main() { int a = 31, b=14; int result=0; result = bitSwapRequired(a, b); printf("Result : [%d]\n", result); return 0; }
void Main() { print(bitSwapRequired(1, -1)); print(bitSwapRequired(31, 14)); }