skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-bitset
This page is read only. You can view the source, but not change it.
# <bitset> **[<bitset>](https://en.cppreference.com/w/cpp/header/bitset)** is a fixed-size bitfield: each bit is independently addressable and can be set, cleared, or tested. It's more memory-efficient than `std::vector<bool>` for large fixed-size bit arrays. Use it for flags, masks, or when you need to track individual bits of a large quantity—like tracking active threads in a thread pool or implementing a sparse boolean matrix. This example sets and manipulates individual bits in an 8-bit set, checking values, counting set bits, and flipping bits. ```cpp // compile: g++ -std=c++11 -o bitsetexample bitsetexample.cpp // run: ./bitsetexample // description: flag management with bitset #include <bitset> #include <iostream> int main() { std::bitset<8> flags; flags.set(2); flags.set(5); std::cout << "bitset: " << flags << "\n"; std::cout << "bit 2 is set: " << flags[2] << "\n"; std::cout << "count of set bits: " << flags.count() << "\n"; flags.flip(2); std::cout << "after flip(2): " << flags << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top