Skip to content

Instantly share code, notes, and snippets.

@mattypiper
Created April 29, 2015 20:15
Show Gist options
  • Save mattypiper/0793a2bfa10c00707bcb to your computer and use it in GitHub Desktop.
Save mattypiper/0793a2bfa10c00707bcb to your computer and use it in GitHub Desktop.
Runtime Endian Detection
uint16_T one = 1U;
enum {
LittleEndian,
BigEndian
} machByteOrder = (*((uint8_T *) &one) == 1U) ? LittleEndian : BigEndian;
switch (machByteOrder) {
case LittleEndian:
// code here
break;
case BigEndian:
// code here
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment