Posts

Showing posts from July, 2020

How to find a machine is little or big endian?

Image
Introduction This article explains the methods used to find out whether a machine is big or little endian Endianness Endianness is the order of sequencing of bytes in computer memory. It can be either Little endian or Big endian. If the LSB is stored first, its little-endian If the MSB is stored first , its big-endian Its is nicely explained in https://en.wikipedia.org/wiki/Endianness Image credit to Wikipedia How data is stored. Thank you Wikipedia! How to find it in a Linux machine? From shell # little $ echo -n I | od -to2 | awk 'FNR==1{ print substr($2,6,1)}' 1 # big $ echo -n I | od -to2 | awk 'FNR==1{ print substr($2,6,1)}' 0 Using tools bala@IND68FL4H2-L:~/study$ lscpu | grep Endian Byte Order: Little Endian If you don't have tools? If you don't have the above tools, a simple program would do the job #include <stdio.h> int main() {      int a = 1;      char *c = (char *) &a;      if (*c)           puts("Little indian");