The Standard ML Basis Library


The PACK_WORD signature


Synopsis

signature PACK_WORD  (* OPTIONAL *)
structure PackWord<N>Big :> PACK_WORD  (* OPTIONAL *)
structure PackWord<N>Little :> PACK_WORD  (* OPTIONAL *)

The PackWord<N>Big and PackWord<N>Little structures provide facilities for packing and unpacking N-bit word elements into Word8 vectors. This mechanism allows word values to be transmitted in binary format over networks. The PackWord<N>Big structures perform big-endian packing and unpacking, while the PackWord<N>Little structures perform little-endian packing and unpacking.


Interface

val bytesPerElem : int
val isBigEndian : bool
val subVec  : Word8Vector.vector * int -> LargeWord.word
val subVecX : Word8Vector.vector * int -> LargeWord.word
val subArr  : Word8Array.array * int -> LargeWord.word
val subArrX : Word8Array.array * int -> LargeWord.word
val update : Word8Array.array * int * LargeWord.word
               -> unit

Description

val bytesPerElem : int
The number of bytes per element. Most implementations will provide several structures with values of bytesPerElem that are small powers of two (e.g., 1, 2, 4, and 8, corresponding to N of 8, 16, 32, 64, respectively).

val isBigEndian : bool
True if the structure implements a big-endian view of the data (most-significant byte first). Otherwise, the structure implements a little-endian view (least-significant byte first).

subVec (vec, i)
subVecX (vec, i)
These extract the subvector
vec[bytesPerElem*i..bytesPerElem*(i+1)-1]
of the vector vec and convert it into a word according to the endianness of the structure. The subVecX version extends the sign bit (most significant bit) when converting the subvector to a word. The functions raise the Subscript exception if i < 0 or if Word8Vector.length vec < bytesPerElem * (i + 1).

subArr (arr, i)
subArrX (arr, i)
These extract the subarray
arr[bytesPerElem*i..bytesPerElem*(i+1)-1]
of the array arr and convert it into a word according to the endianness of the structure. The subArrX version extends the sign bit (most significant bit) when converting the subarray into a word. The functions raise the Subscript exception if i < 0 or if Word8Array.length arr < bytesPerElem * (i+1).

update (arr, i, w)
stores the bytesPerElem low-order bytes of the word w into the bytes bytesPerElem*i through bytesPerElem*(i+1)-1 of the array arr, according to the structure's endianness. It raises the Subscript exception if i < 0 or if Word8Array.length arr < bytesPerElem * (i+1).

See Also

Byte, LargeWord, MONO_ARRAY, MONO_VECTOR, PACK_REAL

[ Top | Parent | Contents | Index | Root ]

Generated April 12, 2004
Last Modified May 29, 2000
Comments to John Reppy.


This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.

Copyright © 2004 AT&T and Lucent Technologies. All rights reserved.

Permission is granted for internet users to make one paper copy for their own personal use. Further hardcopy reproduction is strictly prohibited. Permission to distribute the HTML document electronically on any medium other than the internet must be requested from the copyright holders by contacting the editors. Printed versions of the SML Basis Manual are available from Cambridge University Press. To order, please visit www.cup.org (North America) or www.cup.cam.ac.uk (outside North America).