View source code
Display the source code in std/bitmanip.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.bitmanip.BitArray.opOpAssign - multiple declarations

Function BitArray.opOpAssign

Support for operator op= for BitArray.

BitArray opOpAssign(string op) (
  const BitArray e2
) pure nothrow @nogc scope
if (op == "-" || op == "&" || op == "|" || op == "^");

Example

bool[] ba = [1,0,1,0,1,1,0,1,0,1];
bool[] bb = [1,0,1,1,0];
auto a = BitArray(ba);
auto b = BitArray(bb);
BitArray c = a;
c.length = 5;
c &= b;
writeln(a[5]); // 1
writeln(a[6]); // 0
writeln(a[7]); // 1
writeln(a[8]); // 0
writeln(a[9]); // 1

Example

bool[] ba = [1,0,1,0,1];
bool[] bb = [1,0,1,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);

a &= b;
writeln(a[0]); // 1
writeln(a[1]); // 0
writeln(a[2]); // 1
writeln(a[3]); // 0
writeln(a[4]); // 0

Example

bool[] ba = [1,0,1,0,1];
bool[] bb = [1,0,1,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);

a |= b;
writeln(a[0]); // 1
writeln(a[1]); // 0
writeln(a[2]); // 1
writeln(a[3]); // 1
writeln(a[4]); // 1

Example

bool[] ba = [1,0,1,0,1];
bool[] bb = [1,0,1,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);

a ^= b;
writeln(a[0]); // 0
writeln(a[1]); // 0
writeln(a[2]); // 0
writeln(a[3]); // 1
writeln(a[4]); // 1

Example

bool[] ba = [1,0,1,0,1];
bool[] bb = [1,0,1,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);

a -= b;
writeln(a[0]); // 0
writeln(a[1]); // 0
writeln(a[2]); // 0
writeln(a[3]); // 0
writeln(a[4]); // 1

Function BitArray.opOpAssign

Support for operator ~= for BitArray. Warning: This will overwrite a bit in the final word of the current underlying data regardless of whether it is shared between BitArray objects. i.e. D dynamic array concatenation semantics are not followed

BitArray opOpAssign(string op) (
  bool b
) pure nothrow scope
if (op == "~");

BitArray opOpAssign(string op) (
  BitArray b
) pure nothrow scope
if (op == "~");

Example

bool[] ba = [1,0,1,0,1];

auto a = BitArray(ba);
BitArray b;

b = (a ~= true);
writeln(a[0]); // 1
writeln(a[1]); // 0
writeln(a[2]); // 1
writeln(a[3]); // 0
writeln(a[4]); // 1
writeln(a[5]); // 1

writeln(b); // a

Example

bool[] ba = [1,0];
bool[] bb = [0,1,0];

auto a = BitArray(ba);
auto b = BitArray(bb);
BitArray c;

c = (a ~= b);
writeln(a.length); // 5
writeln(a[0]); // 1
writeln(a[1]); // 0
writeln(a[2]); // 0
writeln(a[3]); // 1
writeln(a[4]); // 0

writeln(c); // a

Function BitArray.opOpAssign

Operator >>= support.

void opOpAssign(string op) (
  size_t nbits
) pure nothrow @nogc
if (op == ">>");

Shifts all the bits in the array to the right by the given number of bits. The rightmost bits are dropped, and 0's are inserted at the back to fill up the vacant bits.

Warning: unused bits in the final word up to the next word boundary may be overwritten by this operation. It does not attempt to preserve bits past the end of the array.

Example

import std.format : format;

auto b = BitArray([1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1]);

b <<= 1;
writeln(format("%b", b)); // "01100_10101101"

b >>= 1;
writeln(format("%b", b)); // "11001_01011010"

b <<= 4;
writeln(format("%b", b)); // "00001_10010101"

b >>= 5;
writeln(format("%b", b)); // "10010_10100000"

b <<= 13;
writeln(format("%b", b)); // "00000_00000000"

b = BitArray([1, 0, 1, 1, 0, 1, 1, 1]);
b >>= 8;
writeln(format("%b", b)); // "00000000"


Function BitArray.opOpAssign

Operator <<= support.

void opOpAssign(string op) (
  size_t nbits
) pure nothrow @nogc
if (op == "<<");

Shifts all the bits in the array to the left by the given number of bits. The leftmost bits are dropped, and 0's are appended to the end to fill up the vacant bits.

Warning: unused bits in the final word up to the next word boundary may be overwritten by this operation. It does not attempt to preserve bits past the end of the array.

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis, Alex Rønne Petersen, Damian Ziemba, Amaury SECHET

License

Boost License 1.0.