bitwise-bit-field, fxbit-field - bit field extract
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
(bitwise-bit-field ei start end)
(fxbit-field fx start end)
Returns the number represented by the bits at the positions
(exclusive), which is the result of the following computation:
(let ((mask (bitwise-not
(bitwise-arithmetic-shift-left -1 end))))
(bitwise-arithmetic-shift-right (bitwise-and ei mask)
(let ((mask (fxnot
(fxarithmetic-shift-left -1 end))))
(fxarithmetic-shift-right (fxand fx mask)
Returns a single exact integer object.
(fxbit-field #b10101111 4 8)
(fxbit-field #b10101111 0 4)
The operation implemented by these procedures shows up when several
fields are encoded in a single integer. A typical example is the code
in a Scheme implementation that parses binary IEEE 754 floating point.
This pattern also appears often in binary file formats, network
protocols, machine code, encryption and much more.
These procedures are new in R6RS. SRFI-151 has the generic procedure
under the name
These procedures can raise exceptions with the following condition types:
- &assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
The arguments start and end must be non-negative and
start must be less than or equal to end. The
procedure requires that all arguments are fixnums.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.