Little endian: Difference between revisions
mNo edit summary |
Added info about the origin of endian-ness |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
Little endian means that integers store the least significant value first from the left. On Intel machines for example 0x01020304 is stored as 04030201 if you were to look at the register value. On the Internet all packets are in [[big endian|big-endian]] order also known as Netbyte order. Meaning 0x01020304 would really come across on the wire as 0x01020304 (you can test this with [[tcpdump]] some day). In order to make use of integers in netbyte order there is a series of byte swap functions that convert the integers. Ie. from netbyte to host order there is the ntohs() for short integers and ntohl() for long integers. To convert the value from host byte order to netbyte order you need to swap with the htons() function for short integers and the htonl() function for long integers. | Little endian means that integers store the least significant value first from the left. On Intel machines for example 0x01020304 is stored as 04030201 if you were to look at the register value. On the Internet all packets are in [[big endian|big-endian]] order also known as Netbyte order. Meaning 0x01020304 would really come across on the wire as 0x01020304 (you can test this with [[tcpdump]] some day). In order to make use of integers in netbyte order there is a series of byte swap functions that convert the integers. Ie. from netbyte to host order there is the ntohs() for short integers and ntohl() for long integers. To convert the value from host byte order to netbyte order you need to swap with the htons() function for short integers and the htonl() function for long integers. | ||
Known little endian computer architectures (in [[ | Known little endian computer architectures (in [[OpenBSD]]) include: | ||
* i386 | * i386 | ||
Line 7: | Line 7: | ||
* alpha | * alpha | ||
* VAX | * VAX | ||
As a bit of trivia, the terms ''Little Endian'' and ''Big Endian'' come from Gulliver's Travels. In his travels, Gulliver encounters the Lilliputians - a race of 6" men and women who have been fighting a multi-generational war over what end to crack an egg on. In yesteryear, endian-ness of a system was often the subject of a [[Holy War]]. |
Latest revision as of 19:14, 15 March 2006
Little endian means that integers store the least significant value first from the left. On Intel machines for example 0x01020304 is stored as 04030201 if you were to look at the register value. On the Internet all packets are in big-endian order also known as Netbyte order. Meaning 0x01020304 would really come across on the wire as 0x01020304 (you can test this with tcpdump some day). In order to make use of integers in netbyte order there is a series of byte swap functions that convert the integers. Ie. from netbyte to host order there is the ntohs() for short integers and ntohl() for long integers. To convert the value from host byte order to netbyte order you need to swap with the htons() function for short integers and the htonl() function for long integers.
Known little endian computer architectures (in OpenBSD) include:
- i386
- amd64
- alpha
- VAX
As a bit of trivia, the terms Little Endian and Big Endian come from Gulliver's Travels. In his travels, Gulliver encounters the Lilliputians - a race of 6" men and women who have been fighting a multi-generational war over what end to crack an egg on. In yesteryear, endian-ness of a system was often the subject of a Holy War.