bitwise-if, fxif - bitwise if
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
(bitwise-if mask a b)
(fxif mask a b)
Returns the number that is the bit-wise "if" of the two's complement
representations of its arguments, i.e. for each bit, if it is 1 in
mask, the corresponding bit in a becomes the value of the
corresponding bit in the result, and if it is 0, the corresponding bit in
b becomes the corresponding bit in the value of the result.
The following are reference implementations from R6RS:
; bitwise-if
(bitwise-ior (bitwise-and mask a)
(bitwise-and (bitwise-not mask) b))
; fxif
(fxior (fxand mask a)
(fxand (fxnot mask) b))
Returns a single value; an exact integer. The fixnum variant returns a fixnum.
(bitwise-if #xf0f0 #x1234 #xABCD) => #x1B3D
(bitwise-if #b00111100 #b11110000 #b00001111) => #b00110011
These procedures are unique to R6RS. Compatible procedures can be found in
SRFI-60 and SRFI-151.
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.
- R7RS
- The assertions described above are errors. Implementations may signal an
error, extend the procedure's domain of definition to include such
arguments, or fail catastrophically.
These procedures first appeared in R6RS which got the idea from SRFI-60.