operator [] method

LogicValue operator [](
  1. int index
)

Returns the ith bit of this LogicValue

The index provided can be positive or negative. For positive index, the indexing is performed from front of the LogicValue. For negative index, the indexing started from last index and goes to front. Note: the index value must follow, -width <= index < width

LogicValue.ofString('1111')[2];  // == LogicValue.one
LogicValue.ofString('0111')[-1]; // == LogicValue.zero
LogicValue.ofString('0100')[-2]; // == LogicValue.one
LogicValue.ofString('0101')[-5]; // Error - out of range
LogicValue.ofString('0101')[10]; // Error - out of range

Implementation

LogicValue operator [](int index) {
  final modifiedIndex = IndexUtilities.wrapIndex(index, width);

  return _getIndex(modifiedIndex);
}