bitwisecopybit, fxcopybit  copy a bit from an integer onto another integer
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
SYNOPSIS
(bitwisecopybit n k bit)
(fxcopybit n k bit)
DESCRIPTION
Returns the result of replacing the
k th
bit of
n
by
bit.
IMPLEMENTATION NOTES
The following are reference implementations from R6RS.
;; bitwisecopybit
(let ((mask (bitwisearithmeticshiftleft 1 k)))
(bitwiseif mask
(bitwisearithmeticshiftleft bit k)
n))
;; fxcopybit
(let ((mask (fxarithmeticshiftleft 1 k)))
(fxif mask
(fxarithmeticshiftleft bit k)
n))
RETURN VALUES
Returns a single value; an exact integer.
EXAMPLES
(bitwisecopybit 0 10 1) => 1024
(bitwisecopybit #x8000 0 1) => #x8001
(bitwisecopybit #x8001 15 0) => #x0001
COMPATIBILITY
These procedures are unique to R6RS. Similar procedures can be found
in SRFI60 and SRFI151.
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,
k must
be nonnegative, and
bit
must be either 0 or 1.
The fixnum variant further requires that
n
is a fixnum and that
k
is nonnegative and less than (fixnumwidth)1.
SEE ALSO
bitwiseif(3scm),
bitwisebitset?(3scm)
STANDARDS
R6RS
HISTORY
These procedures first appeared in R6RS. There was previously a
similar procedure in SRFI60,
copybit.
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/
.
BUGS
If
k
is very large then an implementation might try to allocate an
excessive amount of memory. In normal implementations it is expected
that all practical values of
k
are fixnums.
Markup created by unroff 1.0sc, March 04, 2023.