Q:

Write MACRO to swap the bytes in 32bit Integer Variable

0

Write MACRO to swap the bytes in 32bit Integer Variable

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Swap all odd and even bits... >>
<< Write the macros to set, clear, toggle and check t...