bitwise-bit-set?(3scm)
π bitwise-bit-set?(3scm) β hi bestie, welcome to the Scheme Programmer's Manual β¨
okay so this page is your whole guide to bitwise-bit-set? and fxbit-set?, which live in the Scheme Programmer's Manual (3scm, if you're keeping score π). and yes, it's serving exactly the "is this one single bit alive" energy you'd expect. let's get into it π
πΈ NAME πΈ
bitwise-bit-set?, fxbit-set? β test if a bit is set in an exact integer. that's it, that's the job, and honestly? she ate π
π LIBRARY π
three different doors into the same party, pick whichever import your code already has open:
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
π¦ SYNOPSIS π¦
(bitwise-bit-set? ei k)
(fxbit-set? fx k)
two procedures, two arguments each, no drama β¨
π§ DESCRIPTION π§
okay so the whole vibe: these return #t if the kth bit is 1 in the two's complement representation of ei or fx respectively, and #f otherwise. that's the entire function, no cap. you hand it a number and a bit index, it tells you if that bit is turned on. bit goes brrr or it doesn't π
and because the spec loves being extra, here's the literal result of the following computation β like, this is genuinely what it's computing:
; 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)))))
so the fixnum one has that cheeky little conditional at the top for the top bit β iconic behavior, honestly π«Ά
π RETURN VALUES π
Returns a single boolean object. one value. a #t or a #f. that's it. lowkey the cleanest return contract ever π
β EXAMPLES β
watch her work:
(bitwise-bit-set? #b101 0)
=> #t
(bitwise-bit-set? #b101 1)
=> #f
bit 0 is set in #b101, bit 1 is not. slay. look at the binary, it's right there: 101 π₯
π COMPATIBILITY π
This procedure is new in R6RS. also, SRFI-151 has the similar procedure bit-set?. so if you're on a different SRFI situation, you know where to look π iykyk
π 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. β οΈ yeah, negative k is a no from her, like don't even try it
π₯ SEE ALSO π₯
go read the neighbors, they're all lovely:
π STANDARDS π
R6RS. periodt π
π 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/. genuine main character energy from the docs team fr fr π«Ά
π 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. so like... she's a little wild past the fixnum width, and yes, people have been burned π noted and documented, at least
okay that's the page!! manual bitwise-bit-set?(3scm), dated 2021-03-09, from the scheme-manpages project β go forth, check your bits, and remember: no negative k πβ¨π
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms