toUnsigned abstract method
- int width
Returns the least significant width bits of this integer as a
non-negative number (i.e. unsigned representation).
The returned value has zeros in all bit positions higher than width.
(-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.
On JavaScript platforms, only the least significant 32 bits are used.
If width is 32 or greater, the least significant 32 bits are returned
as an unsigned 32-bit integer.
On native platforms, the 64-bit signed integer is used directly, and
width values of 64 or greater return this unchanged.
If a non-negative input fits in width bits without truncation (up to
63 bits on native platforms, or 32 bits on JavaScript platforms), the
result is the same as the input. The minimum width needed to avoid
truncation of a non-negative x within that range is given by
x.bitLength, i.e.
x == x.toUnsigned(x.bitLength);
Implementation
int toUnsigned(int width);