How to check whether a system is big endian or little endian?

anand picture anand · Nov 15, 2010 · Viewed 78.4k times · Source

How to check whether a system is big endian or little endian?

Answer

belwood picture belwood · Nov 15, 2010

In C, C++

int n = 1;
// little endian if true
if(*(char *)&n == 1) {...}

See also: Perl version