Skip to content

Instantly share code, notes, and snippets.

@jaredscheib
Last active May 27, 2018 04:38
Show Gist options
  • Save jaredscheib/08595d22f73a16622851f93390ec417a to your computer and use it in GitHub Desktop.
Save jaredscheib/08595d22f73a16622851f93390ec417a to your computer and use it in GitHub Desktop.
Determine if computer processor is using little endian or big endian
#include <stdio.h>
int main () {
char x = 'x';
char z = 'z';
__int32_t w = x*(1<<24) + z;
__int32_t* p = &w;
char o = *(char*)p;
if (o == z) {
printf("processor is using little endian");
} else {
printf("processor is using big endian");
}
return 0;
}
// original, unused hardcoded test
int testEndianHardcoded() {
__int32_t x = 0x7800007a;
__int32_t* p = &x;
char y = *((char*)p+3);
printf("%i, %c", x, y);
return 0;
}
// Co-authored by Greg Little
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment