Why are there "htons" and "ntohs"?

I am not sure why htonsand ntohsexist in the standard library. They do exactly the same thing - if I'm not embarrassed in any way!

The same goes for htonland ntohl.

+4
source share
2 answers

They do for self-documenting code that tells the reader whether the data is in host or network mode.

+7
source

This is if the machine has some kind of unusual endianness , other than big-endian or little-endian, which is not one or more simple byte swaps.

, 0x0A0B0C0D 0B 0C 0D 0A, htonl 0x0A0B0C0D, ntohl 0x0C0D0A0B.

- , , - - .

+5

All Articles