belongs to collection: Interview questions on bitwise operators in C
Write MACRO to swap the bytes in 32bit Integer Variable
I have already written this program in endianness conversion. But here I am creating a Macro for the same.
#include <stdio.h> #include <inttypes.h> #define SWAP_BYTES(u32Value) ((u32Value & 0x000000FF) << 24)\ |((u32Value & 0x0000FF00) << 8) \ |((u32Value & 0x00FF0000) >> 8) \ |((u32Value & 0xFF000000) >> 24) int main() { uint32_t u32CheckData = 0x11223344; uint32_t u32Result = 0; u32Result = SWAP_BYTES(u32CheckData); //swap the data printf("0x%x\n",u32Result); return 0; }
Output:
0x44332211
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.
I have already written this program in endianness conversion. But here I am creating a Macro for the same.
Output:
0x44332211
need an explanation for this answer? contact us directly to get an explanation for this answer