FXFIRST-BIT-SET(3scm)
π bitwise-first-bit-set / fxfirst-bit-set β the Scheme Programmer's Manual, but make it cute
okay so bestie, this is the page for bitwise-first-bit-set and fxfirst-bit-set from the Scheme Programmer's Manual (that's the 3scm manual, iykyk). It's literally all about finding the first bit that's set in an integer. Tiny concept, iconic energy. β¨
πΈ NAME
bitwise-first-bit-set, fxfirst-bit-set β first bit set in an integer
π LIBRARY
these are the imports you need, depending on which flavour you're living in:
(import (rnrs)) ;R6RS
(import (rnrs arithmetic bitwise)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
π¦ SYNOPSIS
(bitwise-first-bit-set ei)
(fxfirst-bit-set fx)
π DESCRIPTION
So what it does is: it returns the index of the least significant 1 bit in the two's complement representation of the argument. If the argument is 0, then β1 is returned. That's the whole vibe check. π
The argument to fxfirst-bit-set must be in the implementation's fixnum range β no cap, that's the rule. π«Ά
π RETURN VALUES
Returns a single value; an exact integer. One value, one vibe, no drama. β¨
π EXAMPLES
(bitwise-first-bit-set 0) => -1
(bitwise-first-bit-set 1) => 0
(bitwise-first-bit-set -4) => 2
look at that. ate. π
π APPLICATION USAGE
These procedures have a variety of uses, e.g. for using integers to represent sets, and some bit-hacks. sets made of integers? bit-hacks? obsessed. π§
β RATIONALE
Some CPUs have an instruction that is similar to this procedure, such as the BSF instruction in the x86 ISA. If it was instead defined by user code then it would be much slower. so yeah, hardware said "i got this" and honestly? it did. π₯
π¦ COMPATIBILITY
The fixnum variant of this procedure works with the implementation-defined fixnum range. that's it, that's the note. π
π 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.
bestie if you get this one, check your arg count first. fr fr. π
π SEE ALSO
π STANDARDS
R4RS, IEEE Scheme, R5RS, R6RS, R7RS, SRFI-60, SRFI-143, SRFI-151
π HISTORY
These procedures are new in R6RS. fresh out the box, 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/.
and that's the whole page, bestie π«Ά β source/version situation: this is bitwise-...t-bit-set(3scm), dated 2022-04-09. go find that first set bit and slay π
β¨
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms