bitwise-bit-set?(3scm) Scheme Programmer's Manual bitwise-bit-set?(3scm)

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.

bitwise-arithmetic-shift-right(3scm), bitwise-first-bit-set(3scm), bitwise-length(3scm)

R6RS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

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.
2021-03-09