toString method

  1. @override
String toString(
  1. {bool includeWidth = true}
)
override

Converts this LogicValue to a binary String, including a decorator at the front in SystemVerilog style.

The first digits before the b (for binary) or h (for hex) are the width of the value. If includeWidth is set to false, then the width of the bus and decorator will not be included in the generated String and it will print in binary.

var lv = LogicValue.ofString('1x0');
print(lv); // This prints `3b'1x0`

Implementation

@override
String toString({bool includeWidth = true}) {
  if (isValid && includeWidth) {
    // for ==INT_BITS, still use BigInt so we don't get negatives
    final hexValue = width >= INT_BITS
        ? toBigInt().toUnsigned(width).toRadixString(16)
        : toInt().toRadixString(16);
    return "$width'h$hexValue";
  } else {
    return [
      if (includeWidth) "$width'b",
      ...List<String>.generate(width, (index) => this[index]._bitString())
          .reversed
    ].join();
  }
}