How to print integer literals in binary or hex in haskell?
printBinary 5 => \"0101\"
printHex 5 => \"05\"
Which libraries/functions allo
The Numeric module includes several functions for showing an Integral type at various bases, including showIntAtBase
. Here are some examples of use:
import Numeric (showHex, showIntAtBase)
import Data.Char (intToDigit)
putStrLn $ showHex 12 "" -- prints "c"
putStrLn $ showIntAtBase 2 intToDigit 12 "" -- prints "1100"