(import (rnrs)) ;R6RS (import (rnrs arithmetic bitwise)) ;R6RS (import (rnrs arithmetic fixnums)) ;R6RS
(bitwise-copy-bit-field to start end from) (fxcopy-bit-field to start end from)
; bitwise-copy-bit-field
(let* ((mask1
(bitwise-arithmetic-shift-left -1 start))
(mask2
(bitwise-not
(bitwise-arithmetic-shift-left -1 end)))
(mask (bitwise-and mask1 mask2)))
(bitwise-if mask
(bitwise-arithmetic-shift-left from start)
to))
; fxcopy-bit-field
(let* ((mask1 (fxarithmetic-shift-left -1 start))
(mask2 (fxnot
(fxarithmetic-shift-left -1 end)))
(mask (fxand mask1 mask2))
(mask3 (fxnot (fxarithmetic-shift-left
-1 (- end start)))))
(fxif mask
(fxarithmetic-shift-left (fxand from mask3)
start)
to))
(fxcopy-bit-field #b0000001 2 5 #b1111000)
=> 1
(fxcopy-bit-field #b0000001 2 5 #b0001111)
=> 29
(fxcopy-bit-field #b0001111 2 5 #b0001111)
=> 31
The fixnum variant furthermore requires that all arguments are fixnums and that start and end are less than (fixnum-width).
https://github.com/schemedoc/manpages/.