Open nixawk opened 7 years ago
#include <stdio.h> typedef int bool; #define TRUE 1 #define FALSE 0 typedef unsigned char *byte_ptr; bool is_little_endian(void) { unsigned int x = 0x01234567; return (*((byte_ptr)&x) == 0x01) ? FALSE : TRUE; } int main(void) { printf("%s\n", is_little_endian() ? "little endian" : "big endian"); return 0; }
References