Little endian: Difference between revisions

From Hackepedia
Jump to navigationJump to search
mNo edit summary
m link fixup
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 [[OPenBSD]]) include:
Known little endian computer architectures (in [[OpenBSD]]) include:


* i386
* i386

Revision as of 03:40, 4 December 2005

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