Q:

How to change endianness?

0

How to change endianness?

All Answers

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

In the below image, you can see the conversion.

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
//Function to change the endianess
uint32_t ChangeEndianness(uint32_t u32Value)
{
    uint32_t u32Result = 0;
    u32Result |= (u32Value & 0x000000FF) << 24;
    u32Result |= (u32Value & 0x0000FF00) << 8;
    u32Result |= (u32Value & 0x00FF0000) >> 8;
    u32Result |= (u32Value & 0xFF000000) >> 24;
    return u32Result;
}
int main()
{
    uint32_t u32CheckData  = 0x11223344;
    uint32_t u32ResultData =0;
    u32ResultData = ChangeEndianness(u32CheckData);  //swap the data
    printf("0x%x\n",u32ResultData);
    u32CheckData = u32ResultData;
    u32ResultData = ChangeEndianness(u32CheckData);//again swap the data
    printf("0x%x\n",u32ResultData);
    return 0;
}

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now