int exchangeBits(int num){ double i = 0; int even, ood; int val = num; while (val){ even = num & (int)pow(2.0,i); ood = num & (int)pow(2.0, i + 1); if (even == 0 && ood != 0 || even != 0 && ood == 0){ num ^= (int)pow(2.0, i); num ^= (int)pow(2.0, i + 1); } i += 2; val >>= 2; } return num; }