# CodeGuru Technical FAQs > CodeGuru Individual FAQs >  C++ General: What do 'ntohl()' and 'htonl()' actually do?

## KevinHall

*Q*: What do 'ntohl()' and 'htonl()' actually do?

*A*: 'ntohl()' and 'htonl()' are two of a family of four functions.  The other two functions are 'ntohs()' and 'htons()'.  Here are the descriptions of the functions from a Linux man page:




> The htonl() function converts the unsigned integer hostlong from host byte order to network byte order.
> 
> The htons() function converts the unsigned short integer hostshort from host byte order to network byte order. 
> 
> The ntohl() function converts the unsigned integer netlong from network byte order to host byte order. 
> 
> The ntohs() function converts the unsigned short integer netshort from network byte order to host byte order.


This family of functions convert between host byte order and network byte order.  When the two byte orders are different, this means the endian-ness of the data will be changed.  When the two byte orders are the same, the data will not be changed.  Because of this, these functions should not be used when one simply wants to change endian-ness in a platform independent (portable) way.  This FAQ shows how to change endian-ness in a platform independent way.

*Special notes:*
'ntohs()', 'ntohl()', 'htons()', and 'htonl()' are not part of the C standard, and thus do not guarentee portability.  The POSIX implementations of 'ntohs()', 'ntohl()', 'htons()' and 'htonl()' take arguments of 'uint16_t' and 'uint32_t' argument types and can be found in the header file *netinet/in.h*.  The Windows implementations use 'unsigned short' and 'unsigned long' and can be found in the header file *winsock2.h*.Other variants of 'ntoh_t_()' and 'hton_t_()' may exist on some sytems, such as 'ntohi()'/'htoni()' or 'ntohll()'/'htonll()'.

----------

