u8-list->bytevector, sint-list->bytevector, uint-list->bytevector - convert a list of integers to a bytevector
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs bytevectors)) ;R6RS
SYNOPSIS
(u8-list->bytevector list)
(sint-list->bytevector list endianness size)
(uint-list->bytevector list endianness size)
DESCRIPTION
These procedures convert a list of exact integers to a bytevector
according to
size
and
endianness.
The integers are encoded in the same order as they appear in
list.
The
sint-list->bytevector
procedure uses the two's complement representation and
uint-list->bytevector
is for unsigned integers.
The
u8-list->bytevector
procedure is the same as
bytevector->uint-list
with a size of 1.
RETURN VALUES
Returns a newly allocated bytevector.
EXAMPLES
(u8-list->bytevector '(1 2 3))
=> #vu8(1 2 3)
(uint-list->bytevector '(#xAA55 #x55AA #x4200) (endianness big) 2)
=> #vu8(#xAA #x55 #x55 #xAA #x42 #x0)
(sint-list->bytevector '(-2 -1 0 1 2) (endianness little) 1)
=> #vu8(254 255 0 1 2)
(let ((b (u8-list->bytevector '(1 2 3 255 1 2 1 2))))
(bytevector->sint-list b (endianness little) 2))
=> (513 -253 513 513)
(let ((b (u8-list->bytevector '(1 2 3 255 1 2 1 2))))
(bytevector->uint-list b (endianness little) 2))
=> (513 65283 513 513)
COMPATIBILITY
The
u8-list->bytevector
procedure is absent from R7RS-small. You can use the
bytevector(3scm)
procedure instead, but it uses a variable argument list, which is
usually less efficient. The other procedures have no equivalent
in R7RS-small.
If the returned bytevector would be empty then the returned bytevector
does not have to be newly allocated.
ERRORS
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
-
The wrong number of arguments was passed or an argument was outside its domain.
SEE ALSO
make-bytevector(3scm),
bytevector->u8-list(3scm),
bytevector(3scm),
endianness(7scm)
STANDARDS
R6RS
HISTORY
These procedures are new for R6RS, where they were based on SRFI-74.
AUTHORS
This page is part of the
scheme-manpages
project.
It includes materials from the RnRS documents.
More information can be found at
https://github.com/schemedoc/manpages/
.
Markup created by unroff 1.0sc, March 04, 2023.