toRadixStringAsUnsigned method
Converts this int to a string representation in the given radix
.
This is always interpreted as an unsigned integer, which means that
negative numbers will be interpreted as per their Two's Complement
representation.
In the string representation, lower-case letters are used for digits above '9', with 'a' being 10 and 'f' being 15.
The radix
argument must be 2 or 16.
Example:
// Binary (base 2).
print(12.toRadixStringAsUnsigned(2)); // 1100
print(31.toRadixStringAsUnsigned(2)); // 11111
print(2021.toRadixStringAsUnsigned(2)); // 11111100101
print((-12).toRadixStringAsUnsigned(2)); // 1111111111111111111111111111111111111111111111111111111111110100
// Octal (base 8).
print(12.toRadixStringAsUnsigned(8)); // 14
print(31.toRadixStringAsUnsigned(8)); // 37
print(2021.toRadixStringAsUnsigned(8)); // 3745
print((-12).toRadixStringAsUnsigned(8)); // 1777777777777777777764
// Hexadecimal (base 16).
print(12.toRadixStringAsUnsigned(16)); // c
print(31.toRadixStringAsUnsigned(16)); // 1f
print(2021.toRadixStringAsUnsigned(16)); // 7e5
print((-12).toRadixStringAsUnsigned(16)); // fffffffffffffff4
// Base 36.
print(((35 * 36 + 1).toRadixStringAsUnsigned(36)); // z1
See also toRadixString
Implementation
String toRadixStringAsUnsigned(int radix) {
return BigInt.from(this)
.checkIsSafeInteger()
.toUnsigned(64)
.toRadixString(radix);
}