From 00022fbeda385d7b6ae2eee44f07eecfc6d92015 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Mon, 20 Apr 2020 12:00:23 +0200 Subject: 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 ] ``` --- lib/tests/misc.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/tests') diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 36ddd186d7b7..7d38b56bc211 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -102,6 +102,16 @@ runTests { expected = 9; }; + testToHex = { + expr = toHex 250; + expected = "FA"; + }; + + testToBase = { + expr = toBase 2 6; + expected = [ 1 1 0 ]; + }; + # STRINGS testConcatMapStrings = { -- cgit v1.2.3