BitArray.this
(in bool[] ba) nothrow pureCreates a BitArray from a bool array, such that bool values read from left to right correspond to subsequent bits in the BitArray.
Parameters
ba | Source array of bool values. |
(void[] v, size_t numbits) @nogc nothrow pureCreates a BitArray from the raw contents of the source array. The source array is not copied but simply acts as the underlying array of bits, which stores data as size_t units.
That means a particular care should be taken when passing an array of a type different than size_t, firstly because its length should be a multiple of size_t.sizeof, and secondly because how the bits are mapped:
size_t[] source = [1, 2, 3, 3424234, 724398, 230947, 389492];
enum sbits = size_t.sizeof * 8;
auto ba = BitArray(source, source.length * sbits);
foreach (n; 0 .. source.length * sbits)
{
auto nth_bit = cast(bool) (source[n / sbits] & (1L << (n % sbits)));
assert(ba[n] == nth_bit);
}The least significant bit in any size_t unit is the starting bit of this unit, and the most significant bit is the last bit of this unit. Therefore, passing e.g. an array of ints may result in a different BitArray depending on the processor's endianness.
This constructor is the inverse of opCast.
Parameters
v | Source array. v.length must be a multple of size_t.sizeof. |
numbits | Number of bits to be mapped from the source array, i.e. length of the created BitArray. |
(size_t len, size_t * ptr) @nogc nothrow pure