Skip to content

Instantly share code, notes, and snippets.

@FreedomBen
Last active February 20, 2021 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FreedomBen/38b05f1ad113406ea2c87c02c402d3cb to your computer and use it in GitHub Desktop.
Save FreedomBen/38b05f1ad113406ea2c87c02c402d3cb to your computer and use it in GitHub Desktop.
Bash script to generate and compile a C program to check Endianness of your system. Cleans up after it is done
cat << EOF > check-endianness.c
#include <stdio.h>
int main() {
int n = 1;
// little endian if true
if(*(char *)&n == 1) {
printf("Little endian\n");
} else {
printf("Big endian\n");
}
}
EOF
gcc -o check-endianness check-endianness.c && ./check-endianness && rm check-endianness check-endianness.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment