Notice that 780b
is the byte-swap of 0b78
, which is the low 16 bits of the number you passed in.
The s
in ntohs
is for short
. It operates on uint16_t
quantities. The argument and return type of ntohs
are unsigned int
only because it predates C89 prototypes; in K&R C it was impossible to express that a function took an argument shorter than int
. (The latest POSIX specification seems to have decided that this historical wart is no longer necessary. I can persuade GCC and clang to warn about this mistake, but only by using -Wconversion
, which is not turned on by -Wall
, -Wextra
, nor -pedantic
.)
The function you are looking for is ntohl
. It operates on uint32_t
quantities, which is what you want. (The l
is for long
, but it dates to a time when 64-bit long
was unheard of.)