big-endian-vs-little-endian
big endian, little endian and network byte order
Big-endian and little-endian are two byte order formats that define the order of bytes in a multi-byte data type, such as a word, double word, or longword.
In a big-endian system, the most significant byte (MSB) of a multi-byte value is stored first, while the least significant byte (LSB) is stored last. On the other hand, in a little-endian system, the LSB is stored first and the MSB is stored last.
check the graph below:
Network byte order refers to the standard byte order used in networking protocols. It is also known as big-endian byte order, where the most significant byte (MSB) of a multi-byte value is stored first, while the least significant byte (LSB) is stored last. This order is used for transmitting data across different computer architectures and operating systems, ensuring that the data is interpreted correctly by the receiving system.
we can use some c function to show the differences.
htons
,h
stands for host,n
stands for network,s
stands for shorthtonl
, same above,l
means long here.
those 2 functions try to convert short/long type data from host byte order to network byte order
we also have- ntohs
- ntohl
those do the reverse.
here is an example code:
1 |
|
output:
1 | gabriel@gabriel-HP-ProDesk-600-G2-SFF:~/weixin-github/tcpip-networking/hello-server$ ./conv |