STDC_COUNT_ONES(3)

๐Ÿ“ฆ version 15.1, in freebsd 15.1

๐Ÿ’… STDC_COUNT_ONES(3) โ€” like, the Library Functions Manual, bestie

okay so this is a page from the Library Functions Manual and it's genuinely one of the cutest little functions in libc โ€” it just counts ones for you. slay.


โœจ NAME โœจ

stdc_count_ones โ€” count the ones in an integer ๐Ÿงฎ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

Standard C Library (libc, -lc)

#include <stdbit.h>

unsigned int
stdc_count_ones_uc(unsigned char value);

unsigned int
stdc_count_ones_us(unsigned short value);

unsigned int
stdc_count_ones_ui(unsigned int value);

unsigned int
stdc_count_ones_ul(unsigned long value);

unsigned int
stdc_count_ones_ull(unsigned long long value);

unsigned int
stdc_count_ones(value);

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so the stdc_count_ones_type() family of functions returns the number of bits set to 1 in value โ€” iconic behaviour, no notes.

and value is of type unsigned char, unsigned short, unsigned int, unsigned long, or unsigned long long, for type being uc, us, ui, ul, or ull respectively. so like, one little suffix per width, and they all do the same sweet thing ๐Ÿ’–

this operation is also known as the โ€œpopulation countโ€ (popcount) or โ€œHamming weightโ€ operation โ€” yes she has three names, she's a main character like that ๐Ÿ‘‘

and the stdc_count_ones(value) type-generic macro literally just picks the appropriate stdc_count_ones_type() function based on the type of value. it does the matching for you so you don't have to. bestie behaviour fr fr ๐Ÿซถ


โญ RETURN VALUES โญ

Returns the number of bits set to 1 in value. that's it, that's the whole vibe โœจ


๐ŸŽ€ SEE ALSO ๐ŸŽ€

(the zeros one is her evil twin, go say hi ๐Ÿ’œ)


๐ŸŒˆ STANDARDS ๐ŸŒˆ

The stdc_count_ones_type() family of functions and the stdc_count_ones() type-generic macro conform to .

not me leaving that exactly as-is ๐Ÿ™ˆ the page literally ends that sentence right there, so I'm not about to invent a reference for you. iykyk.

๐Ÿ”ฅ HISTORY ๐Ÿ”ฅ

The stdc_count_ones_type() family of functions and the stdc_count_ones() type-generic macro were added in FreeBSD 15.1. relatively fresh, lowkey a nepo baby of the standards world, we love her anyway ๐Ÿ’…


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Robert Clausecker <fuz@FreeBSD.org> โ€” ty for the bits, king ๐Ÿซถ


and that's the whole page, bestie ๐ŸŽ€ this cutie comes to you from Debian, dated November 9, 2025, and the manual name is STDC_COUNT_ONES(3) if anyone asks. now go count some ones, you're gonna ate ๐Ÿ’–โœจ๐Ÿฆ‹๐ŸŒธ

๐Ÿ“ฆ where this page comes from
  • freebsd 15.1: base 15.1
  • ๐Ÿ“œ the page's license: BSD-2-Clause
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms