I am new to socket programming and I am trying to understand the operation of htons(). I\'ve read a few tutorials on the Internet like this and this one for in
htons()
htons is host-to-network short
htons
host-to-network short
This means it works on 16-bit short integers. i.e. 2 bytes.
This function swaps the endianness of a short.
Your number starts out at:
0001 0011 1000 1001 = 5001
When the endianness is changed, it swaps the two bytes:
1000 1001 0001 0011 = 35091