This library allows you to convert between Int (base 10) and a List Int (base n). It purposely does not tie you to any specific notation to represent the digits.
RadixInt.fromInt (Base 6)
|> RadixInt.toList -- [4,5] (54 in base6 == 34 in base10)
|> List.indexedMap Tuple.pair -- [(0,4),(1,5)]The List lines up its index with the position of each digit. Using Base12 as an example, lets represent 10 as A and 11 as B. Thus, these are all equivalent:
142 -- base10
BA -- base12
[10 11] -- RadixInt.toList num
-- Note: index 0 == position 0 (2 in 142; A in BA)
-- index 1 == position 1 (4 in 142; B in BA)
-- index 2 == position 2 (1 in 142)
-- 142 = 10^2 * 1 + 10^1 * 4 + 10^0 * 2
-- BA = 12^1 * 11 + 12^0 * 10Represents the base (aka radix) of the number being used
Convert an Int with a custom base into a RadixInt
fromInt (Base 6) 36 == RadixIntConvert a RadixInt back into the Elm's base10 Int
toInt (RadixInt.fromInt (Base 16) 24) == 24Convert a List Int of Base to a Maybe RadixInt.
Will return Nothing if any of the Ints represent an invalid number for the given base.
fromList (Base 10) [ 9 , 1 ] == RadixInt with decimal value of 19
fromList (Base 10) [ 10 , 1 ] == Nothing
fromList (Base 10) [ 0, 2 ] == RadixInt with decimal value of 20
Represents a number with any Int base