bytevector->u8-list(3scm) Scheme Programmer's Manual bytevector->u8-list(3scm)

bytevector->u8-list, bytevector->sint-list, bytevector->uint-list - convert a bytevector to a list of integers

(import (rnrs))                     ;R6RS
(import (rnrs bytevectors))         ;R6RS

(bytevector->u8-list bytevector)
(bytevector->sint-list bytevector endianness size)
(bytevector->uint-list bytevector endianness size)

These procedures convert a bytevector to a list of integer objects according to size and endianness. The integers have the same order as the data in bytevector.

The bytevector->u8-list procedure is the same as bytevector->uint-list with a size of 1. It returns a newly allocated list of the octets of bytevector in the same order.

Returns a newly allocated list of exact integer objects.

(let ((b (make-bytevector 4 -127)))
  (bytevector->u8-list b))
          => #vu8(129 129 129 129)
(let ([b (u8-list->bytevector
           '(#x1 #x2 #x3 #xFF #x1 #x2 #x1 #x2))])
  (bytevector->sint-list b (endianness little) #x2))
          => (#x201 #x-FD #x201 #x201)
(let ([b (u8-list->bytevector
           '(#x1 #x2 #x3 #xFF #x1 #x2 #x1 #x2))])
  (bytevector->uint-list b (endianness little) #x2))
          => (#x201 #xFF03 #x201 #x201)

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. In particular, size must be a positive exact integer object and bytevector must be evenly divisible by size.

endianness(3scm), u8-list->bytevector(3scm)

R6RS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

2021-02-28