bitwisebitfield, fxbitfield  bit field extract
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
SYNOPSIS
(bitwisebitfield ei start end)
(fxbitfield fx start end)
DESCRIPTION
Returns the number represented by the bits at the positions
from
start
(inclusive) to
end
(exclusive), which is the result of the following computation:
;; bitwisebitfield
(let ((mask (bitwisenot
(bitwisearithmeticshiftleft 1 end))))
(bitwisearithmeticshiftright (bitwiseand ei mask)
start))
;; fxbitfield
(let ((mask (fxnot
(fxarithmeticshiftleft 1 end))))
(fxarithmeticshiftright (fxand fx mask)
start))
RETURN VALUES
Returns a single exact integer object.
EXAMPLES
(fxbitfield #b10101111 4 8)
=> #b1010
(fxbitfield #b10101111 0 4)
=> #b1111
APPLICATION USAGE
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.
COMPATIBILITY
These procedures are new in R6RS. SRFI151 has the generic procedure
under the name
bitfield.
ERRORS
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 nonnegative and
start must be less than or equal to end. The
fxbitfield
procedure requires that all arguments are fixnums.
SEE ALSO
bitwisearithmeticshift(3scm),
bitwiseand(3scm)
STANDARDS
R6RS
AUTHORS
This page is part of the
schememanpages
project.
It includes materials from the RnRS documents.
More information can be found at
https://github.com/schemedoc/manpages/
.
Markup created by unroff 1.0sc, March 04, 2023.