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

Idiom #68 Create a bitset

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

uses classes;
procedure task;
var 
  x: TBits;
  n: integer;
begin 
  n := $FFF;
  x := TBits.Create(n);
end;
procedure Task;
var
  x: Set Of Byte;
begin
  x:= [2,4,8,16,32,64,256];  
end;
#include <vector>
std::vector<bool> x(n, 0);
import std.bitmanip;
BitArray x;
x.length = n;
import "math/big"
var x *big.Int = new(big.Int)
import Data.Bits
x :: Integer
x = sum [bit i | i <- [1..n], wannaset i]
import java.util.BitSet;
BitSet x = new BitSet(n);
$x = new BitSet($n);
vec($x, $n, 1) = 0;
from __future__ import division
import math
x = bytearray(int(math.ceil(n / 8.0)))
let mut x = vec![bool; n]

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org