decodeBigIntWithSign function
Decode a big integer with arbitrary sign. When: sign == 0: Zero regardless of magnitude sign < 0: Negative sign > 0: Positive
Implementation
// @internal
BigInt decodeBigIntWithSign(int sign, List<int> magnitude) {
if (sign == 0) {
return BigInt.zero;
}
BigInt result;
if (magnitude.length == 1) {
result = BigInt.from(magnitude[0]);
} else {
result = BigInt.from(0);
for (var i = 0; i < magnitude.length; i++) {
var item = magnitude[magnitude.length - i - 1];
result |= (BigInt.from(item) << (8 * i));
}
}
if (result != BigInt.zero) {
result = sign < 0
? result.toSigned(result.bitLength)
: result.toUnsigned(result.bitLength);
}
return result;
}