Webmaster in a Nutshell

Previous Chapter 15 Next
 

15.10 Structure Conversion

pack template, list

Packs the values into a binary structure using template.

unpack template, expr

Unpacks the structure expr into an array, using template.

template is a sequence of characters as follows:

a / A ASCII string, null- / space-padded
b / B Bit string in ascending / descending order
c / C Native / unsigned char value
f / d Single / double float in native format
h / H Hex string, low / high nybble first.
i / I Signed / unsigned integer value
l / L Signed / unsigned long value
n / N Short / long in network (big endian) byte order
s / S Signed / unsigned short value
u / p Uuencoded string / pointer to a string
v / V Short / long in VAX (little endian) byte order
x / @ Null byte / null fill until position
X     Backup a byte

Each character may be followed by a decimal number that will be used as a repeat count; an asterisk (*) specifies all remaining arguments. If the format is preceded with %n, unpack returns an n-bit checksum instead. Spaces may be included in the template for readability purposes.


Previous Home Next
Conversion Functions Book Index String Functions