Course of Raku / Addendum 🆕 / Working with data / Numbers and mathematics / Exercises / One number, three bases

Solution: One number, three bases

Here is a possible solution to the task.

Code

my $n = 255;

say $n.base(2);
say $n.base(8);
say $n.base(16);

🦋 You can find the source code in the file number-bases.raku.

Output

11111111
377
FF

Comments

  1. The .base method renders an integer in any base from 2 to 36, returning a string. 255 is 11111111 in binary and FF in hexadecimal — the largest value that fits in one byte.

Course navigation

One number, three bases   |   Text and strings