STDC_COUNT_ONES(3)
๐ 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
- Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms