vec`,`

EXPR`,`

OFFSET

BITS

This function treats a string (the value of

) as a vector of
unsigned integers, and returns the value of the element specified by
*EXPR*

and *OFFSET*

.
The function may also be assigned to, which causes the element to be
modified.
The purpose of the function is to provide very compact storage of lists of
small integers. The integers may be very small - vectors can hold
numbers that are as small as one bit, resulting in a bitstring.*BITS*

The

specifies how many elements to skip over to find the one you
want. *OFFSET*

is the number of bits per element in the vector, so each
element can contain an unsigned integer in the range
*BITS*`0..(2**`

)*BITS*`-1`

.

must be one of *BITS*`1`

, `2`

, `4`

, `8`

,
`16`

, or
`32`

. As many elements as possible are packed into each byte, and
the ordering is such that `vec($vectorstring,0,1)`

is guaranteed
to go into the lowest bit of the first byte of the string. To find
out the position of the byte in which an element is going to be put,
you have to multiply the

by the number of elements per
byte. When *OFFSET*

is 1, there are eight elements per byte. When
*BITS*

is 2,
there are four elements per byte. When *BITS*

is 4, there are two elements (called nybbles)
per byte. And so on.*BITS*

Regardless of whether your machine is big-endian or little-endian,
`vec($foo, 0, 8)`

always refers to the first byte of string
`$foo`

. See **select** for
examples of bitmaps generated with **vec**.

Vectors created with **vec** can also be
manipulated with the logical operators `|`

,
`&`

, `^`

, and `~`

, which
will assume a bit vector operation is desired when the operands are strings.

A bit vector (

) can be translated to or from
a string of 1s and 0s by supplying a *BITS == 1*`b*`

template to **unpack** or **pack**. Similarly, a vector of nybbles (

) can be translated with an *BITS ==
4*`h*`

template.