bitwise-bit-count(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸŽ€ NAME πŸŽ€

bitwise-bit-count β€” population count, bestie ✨

okay so this is the bitwise-bit-count(3scm) page from the Scheme Programmer's Manual, and we're gonna get you comfy with it πŸ’–


πŸ“š LIBRARY πŸ“š

the imports are giving very R6RS, no cap:

(import (rnrs))                     ;R6RS
(import (rnrs arithmetic bitwise))  ;R6RS
(import (rnrs arithmetic fixnums))  ;R6RS

πŸͺ„ SYNOPSIS πŸͺ„

(bitwise-bit-count ei)
(fxbit-count fx)

πŸ’– DESCRIPTION πŸ’–

If the argument is non-negative, this procedure returns the number of 1 bits in its two's complement representation. slay.

Otherwise, it returns the result of this computation, exactly:

(bitwise-not (bitwise-bit-count (bitwise-not ei)))

like, that's the whole vibe πŸ¦‹


🌟 RETURN VALUES 🌟

Returns a single exact integer object. one exact integer object, periodt πŸ’…


✨ EXAMPLES ✨

these examples are iconic, honestly:

(bitwise-bit-count #b1)
          => 1

(bitwise-bit-count #b1000)
          => 1

(bitwise-bit-count #b1001)
          => 2

(bitwise-bit-count #b-1001)
          => -2

πŸ› οΈ APPLICATION USAGE πŸ› οΈ

This procedure is used to compute the Hamming distance. It's also used in Hash Array Mapped Tries and other applications. iykyk πŸ’œ


🧩 COMPATIBILITY 🧩

This procedure is new in R6RS. SRFI-151 has the similar procedure bit-count.


πŸ’€ 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. For fxbit-count the argument must be a fixnum. yes, that includes the fixnum vibe check πŸ”₯


πŸ‘€ SEE ALSO πŸ‘€


πŸ“œ STANDARDS πŸ“œ

R6RS πŸ‘‘


πŸ•°οΈ HISTORY πŸ•°οΈ

This procedure can be implemented with the popcount procedure in x86-64 processors. This instruction appeared even in some early computers like the IBM Stretch (1961). history class but make it bits 😭


🫢 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/. πŸ’–


xoxo, your Scheme bestie 🫢 β€” source/version: Scheme Programmer's Manual, bitwise-bit-count(3scm), dated 2021-03-08. bye bestie! πŸŽ€

πŸ“¦ where this page comes from