BitArray.opOpAssign

Operator >>= support.

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.

  1. BitArray opOpAssign(BitArray e2)
  2. BitArray opOpAssign(bool b)
  3. BitArray opOpAssign(BitArray b)
  4. void opOpAssign(size_t nbits)
  5. void opOpAssign(size_t nbits)
    struct BitArray
    @nogc pure nothrow
    void
    opOpAssign
    (
    string op
    )
    (
    size_t nbits
    )
    if (
    op == ">>"
    )

Examples

import std.format : format;

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

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

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

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

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

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

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

Meta