Course of Raku / Advanced / More about built-in types / Integers / Exercises / Hex to decimal
Solution: Hex to decimal
Here is a possible solution to the task.
Code
my $n = :16<1A>;
say $n;
say $n.base(16);🦋 You can find the source code in the file hex-to-decimal.raku.
Output
26
1AComments
The radix form
:16<1A>reads1Aas a base-16 number, which equals1 × 16 + 10 = 26. The variable$nnow holds the plain integer.$n.base(16)converts that integer back to a base-16 string, giving1Aagain — confirming that reading a base and printing in a base are inverse operations.
Course navigation
← Hex to decimal | Prime or not →