Skip to content

bitsoflogic/elm-radixint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RadixInt

This swaps between Int (Base 10) and RadixInt (Base Int)

You can use this directly:


RadixInt.fromInt (Base 6) 34
    |> RadixInt.toList -- [4,5] (54 in base6 == 34 in base10)
    |> List.indexedMap Tuple.pair -- [(0,4),(1,5)]

Or, wrap it in a custom type to hide the implementation of the base:

module Senary exposing (Senary, fromInt, toString)

import RadixInt exposing (..)


type alias Senary =
    RadixInt


fromInt : Int -> Senary
fromInt =
    RadixInt.fromInt (Base 6)


toString : Senary -> String
toString s =
    RadixInt.toList s
        |> List.map (\d -> convertDigitToSenaryNotation d)
        |> List.reverse
        |> String.join ""

convertDigitToSenaryNotation: Int -> String
convertDigitToSenaryNotation d =
  String.fromInt d

Allowing you to work with a custom base like this:

Senary.fromInt 34
    |> Senary.toString -- "54"

About

Convert to and from base 10 and any base Int

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages