How to print integer literals in binary or hex in haskell?

前端 未结 8 1185
说谎
说谎 2021-01-30 02:13

How to print integer literals in binary or hex in haskell?

printBinary 5 => \"0101\"

printHex 5 => \"05\"

Which libraries/functions allo

8条回答
  •  孤街浪徒
    2021-01-30 02:38

    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"
    

提交回复
热议问题