How to print integer literals in binary or hex in haskell?
printBinary 5 => \"0101\"
printHex 5 => \"05\"
Which libraries/functions allo
If you import the Numeric
and Data.Char
modules, you can do this:
showIntAtBase 2 intToDigit 10 "" => "1010"
showIntAtBase 16 intToDigit 1023 "" => "3ff"
This will work for any bases up to 16, since this is all that intToDigit
works for. The reason for the extra empty string argument in the examples above is that showIntAtBase
returns a function of type ShowS
, which will concatenate the display representation onto an existing string.