withSet method

LogicValue withSet(
  1. int startIndex,
  2. LogicValue update
)

Returns a copy of this LogicValue with the bits starting from startIndex up until startIndex + update.width set to update instead of their original value.

The return value will be the same width. An exception will be thrown if the position of the update would cause an overrun past the width.

Implementation

LogicValue withSet(int startIndex, LogicValue update) {
  if (startIndex + update.width > width) {
    throw Exception(
        'Width of updatedValue $update at startIndex $startIndex would'
        ' overrun the width of the original ($width).');
  }

  return [
    getRange(startIndex + update.width, width),
    update,
    getRange(0, startIndex),
  ].swizzle();
}