Methods by type

parse-base — read a number in any radix

Full

Parse a string of digits in a given base into an Int — the inverse of .base.

.parse-base(radix) reads a string written in that radix and returns the Int it denotes. It's the inverse of .base, which renders an integer into a radix.

Parsing from a base #

say "ff".parse-base(16);
say "101".parse-base(2);
Output
255
5

"ff" in base 16 is 255; "101" in base 2 is 5.

Round-trip with .base #

.base renders an Int into a radix string; .parse-base reads it back — the two are exact inverses.

say 255.base(16);
say "FF".parse-base(16);
say 42.base(2).parse-base(2);
Output
FF
255
42

Rendering 42 to binary and parsing it back returns 42 unchanged.

Notes #