The Input is 0x1234 and I want the output as 0x2143 but I am getting 0x4321
#include <stdio.h>
#define SWAP(num) (((num) & 0x0F) << 4) | (((num) & 0xF0) >> 4)
int main() {
short input = 0x1234;
short output = SWAP(input);
print("Input: 0x%04X\n", input);
print("Output: 0x%04X\n", output);
return 0;
}
You're not getting 0x4321, but 0x0043. You forgot about the higher byte and you wrote
printinstead ofprintf. Code below does what you want.