Logo

Programming-Idioms

  • C++
  • Java

Idiom #68 Create a bitset

Create an object x to store n bits (n being potentially large).

import java.util.BitSet;
BitSet x = new BitSet(n);

The bitset will be able to grow if needed.
#include <bitset>
std::bitset<n> x;
#include <vector>
std::vector<bool> x(n, 0);

This will create a vector of n bits initialized to 0.
using System.Collections;
new BitArray(n);

New implementation...
< >
programming-idioms.org