Overview:
- The function ntohs() converts a two-byte integer from network byte order to host byte order.
- It does the inverse operation of the htons() function.
- When the size of the integer to be converted is greater than 16 bytes ntohs() raises an exception stating "OverflowError: ntohs: Python int too large to convert to C 16-bit unsigned integer".
Example:
# Example Python program that converts a two-byte print("Byte order of the host:%s endian"%sys.byteorder) # 16-bit integer to be converted # Convert to network order first print("Network byte order: %s"%nwNum.to_bytes(2, byteorder='little')) |
Output:
Byte order of the host:little endian 65279 65534 Network byte order: b'\xff\xfe' Host byte order:b'\xfe\xff' |