# (chibi bytevector)

Additional bytevector utilities.

## Additional accessors

#### `(bytevector-u16-ref-le bv i)`

Retrieve a 16-bit unsigned integer value from the given bytevector `bv` at offset `i`, in little-endian order.

#### `(bytevector-u16-ref-be bv i)`

Retrieve a 16-bit unsigned integer value from the given bytevector `bv` at offset `i`, in big-endian order.

#### `(bytevector-u32-ref-le bv i)`

Retrieve a 32-bit unsigned integer value from the given bytevector `bv` at offset `i`, in little-endian order.

#### `(bytevector-u32-ref-be bv i)`

Retrieve a 32-bit unsigned integer value from the given bytevector `bv` at offset `i`, in big-endian order.

## Bignum encodings

#### `(bytevector-ber-ref bv [i end])`

A BER compressed integer (X.209) is an unsigned integer in base 128, most significant digit first, where the high bit is set on all but the final (least significant) byte. Thus any size integer can be encoded, but the encoding is efficient and small integers don't take up any more space than they would in normal char/short/int encodings.

#### `(bytevector-ber-set! bv n [start end])`

## Integer conversion

#### `(integer->bytevector n)`

Convert an unsigned integer `n` to a bytevector representing the base-256 big-endian form (the zero index holds the MSB).

#### `(bytevector->integer bv)`

The inverse of `integer->bytevector`. Convert a bytevector representing the base-256 big-endian form (the zero index holds the MSB) to the corresponding unsigned integer.

#### `(bytevector-pad-left bv len)`

Utility to pad a bytevector with zeros. Padding is added to the left so as not to change the big-endian value.

## Hex string conversion

#### `(integer->hex-string n)`

Big-endian conversion, guaranteed padded to even length.

#### `(hex-string->integer str)`

#### `(bytevector->hex-string bv)`

#### `(hex-string->bytevector str)`