bitwise-bit-set?, fxbit-set? - test if a bit is set in an exact integer
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
(bitwise-bit-set? ei k)
(fxbit-set? fx k)
Returns #t if the kth bit is 1 in the two's complement
representation of ei or fx, respectively, and #f
otherwise.
This is the result of the following computation:
; bitwise-bit-set?
(not (zero? (bitwise-and (bitwise-arithmetic-shift-left 1 k)
ei)))
; fxbit-set?
(if (fx>=? k (fx- (fixnum-width) 1))
(fxnegative? fx)
(not (fxzero? (fxand fx (fxarithmetic-shift-left 1 k)))))
Returns a single boolean object.
(bitwise-bit-set? #b101 0)
=> #t
(bitwise-bit-set? #b101 1)
=> #f
This procedure is new in R6RS. SRFI-151 has the similar procedure
bit-set?.
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. Raised if k is negative.
Note that even in the fixnum variant, k is allowed to be greater than the
fixnum width. There have been bugs related to this aspect in Sagittarius 0.4.9
and IronScheme TFS:101169.