Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Js

Idiom #68 Create a bitset

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

let x = new Buffer (Math.ceil (n / 8))

Buffers allocate bytes, so we divide n by 8 and take the ceiling of n
#include <vector>
std::vector<bool> x(n, 0);

This will create a vector of n bits initialized to 0.

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