#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main(void)
{
uint32_t u32RawData;
uint8_t *pu8CheckData;
u32RawData = 0x11223344; //Assign data
pu8CheckData = (uint8_t *)&u32RawData; //Type cast
if (*pu8CheckData == 0x44) //check the value of lower address
{
printf("little-Endian");
}
else if (*pu8CheckData == 0x11) //check the value of lower address
{
printf("big-Endian");
}
return 0;
}
Method 2:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
typedef union
{
uint32_t u32RawData; // integer variable
uint8_t au8DataBuff[4]; //array of character
} RawData;
int main(void)
{
RawData uCheckEndianess;
uCheckEndianess.u32RawData = 0x11223344; //assign the value
if (uCheckEndianess.au8DataBuff[0] == 0x44) //check the array first index value
{
printf("little-endian");
}
else if (uCheckEndianess.au8DataBuff[0] == 0x11) //check the array first index value
{
printf("big-endian");
}
return 0;
}
Method 1:
Method 2:
need an explanation for this answer? contact us directly to get an explanation for this answer