htons() function in socket programing

前端 未结 4 624
执笔经年
执笔经年 2020-12-22 19:06

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

4条回答
  •  甜味超标
    2020-12-22 19:35

    htons is 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

提交回复
热议问题