W3cubDocs

/Dart 2

toUnsigned method

BigInt toUnsigned (int width)

Returns the least significant width bits of this big integer as a non-negative number (i.e. unsigned representation). The returned value has zeros in all bit positions higher than width.

new BigInt.from(-1).toUnsigned(5) == 31   // 11111111  ->  00011111

This operation can be used to simulate arithmetic from low level languages. For example, to increment an 8 bit quantity:

q = (q + 1).toUnsigned(8);

q will count from 0 up to 255 and then wrap around to 0.

If the input fits in width bits without truncation, the result is the same as the input. The minimum width needed to avoid truncation of x is given by x.bitLength, i.e.

x == x.toUnsigned(x.bitLength);

Implementation

BigInt toUnsigned(int width);

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-core/BigInt/toUnsigned.html