bytevector->u8-list(3scm)
β¨ bytevector->u8-list, bytevector->sint-list, bytevector->uint-list β¨
okay bestie, welcome to the Scheme Programmer's Manual π β we're talking about three little icon procedures today, and honestly? they ate.
π LIBRARY π
(import (rnrs)) ;R6RS
(import (rnrs bytevectors)) ;R6RS
so you can pull these from either one, no cap π«Ά
πΈ SYNOPSIS πΈ
(bytevector->u8-list bytevector)
(bytevector->sint-list bytevector endianness size)
(bytevector->uint-list bytevector endianness size)
like, that's the whole vibe check right there π
π¦ DESCRIPTION π¦
okay so these procedures convert a bytevector into a list of integer objects π β and they do it according to size and endianness (iykyk). the integers land in the same order as the data sitting in bytevector, so no sneaky reordering, fr fr.
and bytevector->u8-list? she's literally the same as bytevector->uint-list with a size of 1. periodt. she returns a newly allocated list of the octets of bytevector, in the exact same order π
β RETURN VALUES β
returns a newly allocated list of exact integer objects π (new list, fresh out the oven, no shared structure shenanigans)
π₯ EXAMPLES π₯
first one, beware β this is the example straight from the page, shameless and iconic:
(let ((b (make-bytevector 4 -127)))
(bytevector->u8-list b))
=> #vu8(129 129 129 129)
next up, the signed girly with (endianness little):
(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)
and the unsigned version, same bytes, different energy:
(let ([b (u8-list->bytevector
'(#x1 #x2 #x3 #xFF #x1 #x2 #x1 #x2))])
(bytevector->uint-list b (endianness little) #x2))
=> (#x201 #xFF03 #x201 #x201)
see how #x-FD vs #xFF03 be doing the most? that's the whole signed/unsigned main character energy right there πβ¨
π ERRORS π
these procedures can raise exceptions with the following condition types:
&assertion(R6RS) β wrong number of arguments got passed, or an argument was outside its domain. in particular:sizemust be a positive exact integer object, and bytevector must be evenly divisible bysize. so like, don't try to be cute and pass a weird size, she WILL throw π
π SEE ALSO π
endianness(7scm)u8-list->bytevector(3scm)
go read those too, they're besties with these procedures π§
π STANDARDS π
R6RS β
π AUTHORS π
this page is part of the scheme-manpages project π it includes materials from the RnRS documents, and more info can be found at https://github.com/schemedoc/manpages/ β go show them some love π«Ά
and that's the tea, bestie β scheme-manpages, 2021-02-28, bytevector->u8-list(3scm), signing off π
β¨π
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms