26.3. Data conversion

Data conversion functions are provided to convert both from the foreign system to the host, and from the host to the foreign system. Before we look at these functions, some definitions:

host

The system that is running our program.

foreign system

The system that produced the data we are trying to process. This could be the same system as the host or a different system. This could have the same or different native byte ordering than the host.

Functions are provided that allow you to convert shorts and longs in either direction. These functions are described more completely in the cvt reference page. Briefly however:

ftohl

Converts a longword (32 bit integer) from foreign to host format.

ftohw

Converts a short (16 bit word) from foreign to host format.

htofl

Converts a longword (32 bit integer) from host to foreign system format.

htofs

Converts a short (16 bit integer) from host to foreign system format.