Non-decimal radices/Convert: Difference between revisions

m
No edit summary
m (→‎{{header|Haskell}}: Minor tidying)
Line 1,378:
If we want to assume a default character set, then a general '''toBase''' (Int -> Int -> String) can be also be derived from '''inBaseDigits'''.
 
<lang haskell>import Data.ListChar (unfoldrintToDigit)
import Data.CharList (intToDigitunfoldr)
 
inBaseDigits :: [Char]String -> Int -> String
inBaseDigits ds n = reverse $ unfoldr go n
where
let base = length ds
in reverse $
go unfoldrx
| 0 < (\x ->=
let (d, r) (if= xquotRem >x 0base
in Just (ds !! r, then let (d, r) = quotRem x base
| otherwise else= Nothing))
in Just (ds !! r, d)
else Nothing))
n
 
inLowerHex :: Int -> String
Line 1,412 ⟶ 1,410:
 
toBase :: Int -> Int -> String
toBase intBase n =
if| (intBase < 36) && (intBase > 0) =
then inBaseDigits (take intBase (['0' .. '9'] ++ ['a' .. 'z'])) n
| otherwise else= []
 
main :: IO ()
9,655

edits