toIntUnsigned method Null safety
- int width
Returns this BigInt as an int.
Always interprets the number as unsigned, and thus never clamps to fit.
Implementation
int toIntUnsigned(int width) {
if (width > LogicValue._INT_BITS) {
throw Exception('Cannot convert to BigInt when width $width'
' is greater than ${LogicValue._INT_BITS}');
} else if (width == LogicValue._INT_BITS) {
// When width is 64, `BigInt.toInt()` will clamp values assuming that
// it's a signed number. To avoid that, if the width is 64, then do the
// conversion in two 32-bit chunks and bitwise-or them together.
const maskWidth = 32;
final mask = _BigLogicValue._maskOfWidth(maskWidth);
return (this & mask).toInt() |
(((this >> maskWidth) & mask).toInt() << maskWidth);
} else {
return toInt();
}
}