bitwisecopybitfield, fxcopybitfield  copy a bitfield from one integer onto another
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
SYNOPSIS
(bitwisecopybitfield to start end from)
(fxcopybitfield to start end from)
DESCRIPTION
Returns the result of replacing in
to
the bits at positions from
start
(inclusive) to
end
(exclusive) by the bits in
from
from position 0 (inclusive) to
position
end−start
(exclusive).
IMPLEMENTATION NOTES
The following are reference implementations from R6RS.
; bitwisecopybitfield
(let* ((mask1
(bitwisearithmeticshiftleft 1 start))
(mask2
(bitwisenot
(bitwisearithmeticshiftleft 1 end)))
(mask (bitwiseand mask1 mask2)))
(bitwiseif mask
(bitwisearithmeticshiftleft from start)
to))
; fxcopybitfield
(let* ((mask1 (fxarithmeticshiftleft 1 start))
(mask2 (fxnot
(fxarithmeticshiftleft 1 end)))
(mask (fxand mask1 mask2))
(mask3 (fxnot (fxarithmeticshiftleft
1 ( end start)))))
(fxif mask
(fxarithmeticshiftleft (fxand from mask3)
start)
to))
RETURN VALUES
Returns a single value; an exact integer. The fixnum variant returns a
fixnum.
EXAMPLES
(fxcopybitfield #b0000001 2 5 #b1111000)
=> 1
(fxcopybitfield #b0000001 2 5 #b0001111)
=> 29
(fxcopybitfield #b0001111 2 5 #b0001111)
=> 31
COMPATIBILITY
This procedure is unique to R6RS.
ERRORS
This procedure can raise exceptions with the following condition types:
 &assertion (R6RS)

The wrong number of arguments was passed or an argument was outside its domain.
In particular,
start
and
end
must be nonnegative, and
start
must be less than or equal to
end.
The fixnum variant furthermore requires that all arguments are
fixnums and that
start
and
end
are less than (fixnumwidth).
SEE ALSO
bitwisecopybit(3scm),
bitwisebitfield(3scm),
bitwiseior(3scm)
bitwisearithmeticshift(3scm)
STANDARDS
R6RS
HISTORY
These procedures first appeared in R6RS. There is a similar procedure
in SRFI60 that uses a different argument order,
copybitfield.
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.