(import (rnrs)) ;R6RS (import (rnrs bytevectors)) ;R6RS
(bytevector-s16-set! bytevector k n endianness) (bytevector-s32-set! bytevector k n endianness) (bytevector-s64-set! bytevector k n endianness) (bytevector-u16-set! bytevector k n endianness) (bytevector-u32-set! bytevector k n endianness) (bytevector-u64-set! bytevector k n endianness) (bytevector-ieee-double-set! bytevector k x endianness) (bytevector-ieee-single-set! bytevector k x endianness) (bytevector-s16-native-set! bytevector k n) (bytevector-s32-native-set! bytevector k n) (bytevector-s64-native-set! bytevector k n) (bytevector-u16-native-set! bytevector k n) (bytevector-u32-native-set! bytevector k n) (bytevector-u64-native-set! bytevector k n) (bytevector-ieee-double-native-set! bytevector k x) (bytevector-ieee-single-native-set! bytevector k x)
The signed variants use the two's complement representation.
The endianness is normally one of the following symbols:
The -native variants use the machine's native endianness and furthermore impose an alignment requirement: the index k must be evenly divisible by the data type size (2, 4 or 8). Such an access is said to be aligned, as opposed to an unaligned access.
The number of bytes m used depends on the data type and is either two, four or eight (corresponding to 16, 32 or 64 bits). The bytevector must be at least k+m bytes in length.
The integer n must be in the range [0, (2^w)-1] for the unsigned operations and in the range [-(2^(w-1)), (2^(w-1))-1] for the signed operations, where w is the size of the data type in bits. For the floating point operations, x must be a real number object.
Unlike the equivalent operation in e.g. C, the index is not multiplied by the element size.
(define b (u8-list->bytevector '(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 253))) (bytevector-u16-set! b 0 12345 (endianness little)) (bytevector-u16-ref b 0 (endianness little)) => 12345 (bytevector-u16-native-set! b 0 12345) (bytevector-u16-native-ref b 0) => 12345 (bytevector-u16-ref b 0 (endianness little)) => unspecified
https://github.com/schemedoc/manpages/
.