The OpenD Programming Language

BitArray.toString

Return a string representation of this BitArray.

Two format specifiers are supported:

  • %s which prints the bits as an array, and
  • %b which prints the bits as 8-bit byte packets
  • separated with an underscore.

    struct BitArray
    const
    void
    toString
    (
    W
    )
    (
    ref W sink
    ,
    scope const ref FormatSpec!char fmt
    )
    if (
    isOutputRange!(W, char)
    )

    Parameters

    sink W

    A char accepting output range.

    fmt FormatSpec!char

    A std.format.FormatSpec which controls how the data is displayed.

    Examples

    import std.format : format;
    
    auto b = BitArray([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]);
    
    auto s1 = format("%s", b);
    assert(s1 == "[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]");
    
    auto s2 = format("%b", b);
    assert(s2 == "00001111_00001111");
    

    Meta