htonl, htons, ntohl and ntohs Functions

Purpose

Functions to convert between Host and Network TCP/IP formats.

Syntax

network-long = htonl (host-long)
network-short = htons (host-short)
host-long = ntohl (network-long)
host-short = ntohs (network-short)

network-long: A 32-bit number in TCP/IP network byte order.
network-short: A 16-bit number in TCP/IP network byte order.
host-long: A 32-bit number in host byte order.
host-short: A 16-bit number in host byte order.

Description

The Windows Sockets functions convert between Host (Little Endian) values and Network TCP/IP (Big Endian) values.

Example

Local h% = 10444887     // Host Value

Local n% = htonl(h%)    // TCP/IP Value

Trace Bin(h%, 32)       // Little Endian (low byte first)

Trace Bin(n%, 32)       // Big Endian (high byte first)

Debug.Show

See Also

{Created by Sjouke Hamstra; Last updated: 16/01/2023 by James Gaite; Other Contributors: Jean-Marie Melanson}