lib: add the toHex and toBase utility functions

`toHex` converts the given positive integer to a string of the hexadecimal
representation of that integer. For example:

```
toHex 0 => "0"

toHex 16 => "10"

toHex 250 => "FA"
```

`toBase base i` converts the positive integer `i` to a list of it
digits in the given `base`. For example:

```
toBase 10 123 => [ 1 2 3 ]

toBase 2 6 => [ 1 1 0 ]

toBase 16 250 => [ 15 10 ]
```
This commit is contained in:
Bas van Dijk
2020-04-20 12:00:23 +02:00
parent d0c12dc612
commit 00022fbeda
3 changed files with 62 additions and 1 deletions

View File

@@ -102,6 +102,16 @@ runTests {
expected = 9;
};
testToHex = {
expr = toHex 250;
expected = "FA";
};
testToBase = {
expr = toBase 2 6;
expected = [ 1 1 0 ];
};
# STRINGS
testConcatMapStrings = {