Next: , Previous: , Up: stdlib   [Index]


5.2 Bytevectors

Many applications deal with blocks of binary data by accessing them in various ways—extracting signed or unsigned numbers of various sizes. Therefore, the (rnrs bytevectors (6)) library provides a single type for blocks of binary data with multiple ways to access that data. It deals with integers and floating–point representations in various sizes with specified endianness.

Bytevectors are objects of a disjoint type. Conceptually, a bytevector represents a sequence of 8-bit bytes. The description of bytevectors uses the term byte for an exact integer object in the interval (-128, …, 127) and the term octet for an exact integer object in the interval (0, …, 255). A byte corresponds to its two’s complement representation as an octet.

The length of a bytevector is the number of bytes it contains. This number is fixed. A valid index into a bytevector is an exact, non–negative integer object less than the length of the bytevector. The first byte of a bytevector has index 0; the last byte has an index one less than the length of the bytevector.

Generally, the access procedures come in different flavors according to the size of the represented integer and the endianness of the representation. The procedures also distinguish signed and unsigned representations. The signed representations all use two’s complement.

Like string literals, literals representing bytevectors do not need to be quoted:

#vu8(12 23 123)         ⇒ #vu8(12 23 123)

Next: , Previous: , Up: stdlib   [Index]