(import (rnrs)) ;R6RS (import (rnrs bytevectors)) ;R6RS
(bytevector-sint-ref bytevector k endianness size) (bytevector-uint-ref bytevector k endianness size) (bytevector-sint-set! bytevector k n endianness size) (bytevector-uint-set! bytevector k n endianness size)
The bytevector-sint-ref and bytevector-uint-ref procedures decode a signed or unsigned integer (respectively) from bytevector, starting from index k, according to endianness, reading size bytes.
The integers are encoded according to signedness, endianness and size. Signed or unsigned is chosen by using the appropriate procedure. The size argument is a positive exact integer that determines how many bytes the encoded integer uses (a 128-bit integer would have a size of 16). The endianness is normally one of these symbols:
The signed variants use the two's complement representation. The range that can be encoded by the unsigned variants is [0,(256^size)−1]. The range of the signed variants is [−(256^size)/2,((256^size)/2)-1].
The bytevector-sint-set! and bytevector-uint-set! procedures return unspecified values.
(define b (make-bytevector 16 -127)) ;; Using (endianness little) is the same as writing ;; (quote little), but it gives a free typo check. (bytevector-uint-set! b 0 (- (expt 2 128) 3) (endianness little) 16) (bytevector-uint-ref b 0 (endianness little) 16) => #xfffffffffffffffffffffffffffffffd (bytevector-sint-ref b 0 (endianness little) 16) => -3 (bytevector->u8-list b) => (253 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255) (bytevector-uint-set! b 0 (- (expt 2 128) 3) (endianness big) 16) (bytevector-uint-ref b 0 (endianness big) 16) => #xfffffffffffffffffffffffffffffffd (bytevector-sint-ref b 0 (endianness big) 16) => -3 (bytevector->u8-list b) => (255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 253))
They are sometimes used in code that is easier to express as operations on integers rather than bytevectors.
https://github.com/schemedoc/manpages/
.