zeroExtend method

Logic zeroExtend(
  1. int newWidth
)

Returns a Logic with width newWidth where new bits added are zeros as the most significant bits.

The newWidth must be greater than or equal to the current width or an exception will be thrown. When newWidth equals the current width, this returns the original signal (same object identity).

If isNet, then the result will also be a net.

Implementation

Logic zeroExtend(int newWidth) {
  if (newWidth < width) {
    throw Exception(
      'New width $newWidth must be greater than or equal to width $width.',
    );
  }
  // Nothing to extend: reuse the original signal instead of building a
  // zero-width Const + Concat (matches signExtend's same-width path).
  if (newWidth == width) {
    return this;
  }
  // Nothing to extend: reuse the original signal instead of building a
  // zero-width Const + Concat (matches signExtend's same-width path).
  if (newWidth == width) {
    return this;
  }
  return [
    Const(0, width: newWidth - width),
    this,
  ].concat();
}