bitwise-bit-set?, fxbit-set? - test if a bit is set in an exact integer
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
SYNOPSIS
(bitwise-bit-set? ei k)
(fxbit-set? fx k)
DESCRIPTION
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)))))
RETURN VALUES
Returns a single boolean object.
EXAMPLES
(bitwise-bit-set? #b101 0)
=> #t
(bitwise-bit-set? #b101 1)
=> #f
COMPATIBILITY
This procedure is new in R6RS. SRFI-151 has the similar procedure
bit-set?.
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.
Raised if k is negative.
SEE ALSO
bitwise-arithmetic-shift-right(3scm),
bitwise-first-bit-set(3scm),
bitwise-length(3scm)
STANDARDS
R6RS
AUTHORS
This page is part of the
scheme-manpages
project.
It includes materials from the RnRS documents.
More information can be found at
https://github.com/schemedoc/manpages/
.
BUGS
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.
Markup created by unroff 1.0sc, March 04, 2023.