bitwiserotatebitfield, fxrotatebitfield  bitwise rotate left
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
SYNOPSIS
(bitwiserotatebitfield n start end count)
(fxrotatebitfield n start end count)
DESCRIPTION
Returns the result of cyclically permuting in
n
the bits at positions from
start
(inclusive)
to
end
(exclusive) by
bits
towards the more significant bits.
IMPLEMENTATION NOTES
The following are reference implementations from R6RS.
;; bitwiserotatebitfield
(let ((width ( end start)))
(if (positive? width)
(let* ((count (mod count width))
(field0
(bitwisebitfield n start end))
(field1 (bitwisearithmeticshiftleft
field0 count))
(field2 (bitwisearithmeticshiftright
field0
( width count)))
(field (bitwiseior field1 field2)))
(bitwisecopybitfield n start end field))
n))
;; fxrotatebitfield
(let ((width (fx end start)))
(fxcopybitfield n start end
(fxior
(fxarithmeticshiftleft
(fxbitfield n start (fx end count))
count)
(fxarithmeticshiftright
(fxbitfield n start end)
(fx width count)))))
RETURN VALUES
Returns a single value; an exact integer.
EXAMPLES
(fxrotatebitfield #x1234 4 12 4) => #x1324
APPLICATION USAGE
Bitwise rotation is a common operation in cryptography.
COMPATIBILITY
These procedures are unique to R6RS. Similar alternatives can be found
in SRFI60 and SRFI151.
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. In particular, all arguments must be exact integers,
start, end and count must be nonnegative, and
start must be less than or equal to end.
For the fixnum variant there are further restrictions. All arguments
must be fixnums, and start, end and count must be
less than the implementation's fixnum width, and count must be
less than or equal to endstart.
SEE ALSO
bitwiserotatebitfield(3scm),
bitwisearithmeticshift(3scm),
bitwisecopybitfield(3scm)
STANDARDS
R6RS.
HISTORY
Many processor instruction set architectures have an integer rotate
instruction. R6RS was the first Scheme report to standardize this
operation. Previously SRFI60 had slightly different
bitfieldrotate
procedure. Early Scheme running on MacLISP had access to the
rot
procedure that rotated a whole 36bit fixnum by some amount.
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.