signExtend method
- int newWidth
Returns a new Logic width width newWidth where new bits added are sign
bits as the most significant bits. The sign is determined using two's
complement, so it takes the most significant bit of the original signal
and extends with that.
The newWidth must be greater than or equal to the current width or
an exception will be thrown.
If isNet, then the result will also be a net.
Implementation
Logic signExtend(int newWidth) {
if (width == 1) {
return replicate(newWidth);
} else if (newWidth > width) {
return [
this[-1].replicate(newWidth - width),
this,
].swizzle();
} else if (newWidth == width) {
return this;
}
throw Exception(
'New width $newWidth must be greater than or equal to width $width.');
}