Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

endianness

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

like image 628
anand Avatar asked Nov 15 '10 06:11

anand


People also ask

Is there a quick way to determine endianness of your machine?

We can also check the endianness of the machine using the union. We need to create a union that has an integer variable and an array of 4 characters. If the first element (au8DataBuff [0]) of the character array is equal to the LSB Bytes of integer, then the system will be little endian otherwise big-endian.

What is the difference between little endianness and big endianness?

Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first, at the lowest storage address. Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first.

Is x86 64 big or little-endian?

The x86 processors use little-endian byte ordering. The least significant byte (LSB) of an integer is stored at the lowest address of the integer. The most significant byte is stored at the highest address for data items in this processor.


1 Answers

In C, C++

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

See also: Perl version

like image 156
belwood Avatar answered Oct 06 '22 08:10

belwood