This program will swap two bytes/words of an integer number, here this operation is implemented using bitwise shifting and bit masking.
/* C program to swap bytes/words of integer number.*/
unsigned int data = 0x1234;
printf("\ndata before swapping : %04X", data);
data = ((data << 8) & 0xff00) | ((data >> 8) & 0x00ff);
printf("\ndata after swapping : %04X", data);
data before swapping : 1234
data after swapping : 3412
total answers (1)
start bookmarking useful questions and collections and save it into your
own study-lists, login now to start creating your own collections.