在 module中,我发现了以下函数showIntAtBase。我可以把十进制数字转换成二进制或八进制数字吗?
这个函数是这样工作的吗?
showIntAtBase 6 1025554775 = 245433110435
showIntAtBase 2 5264564526752765267240006 = 10001011010110100001001110101100111000111110101011111100100100001010110010001000110如果不是这样的话,你能告诉我任何预定义的吗?
发布于 2018-01-29 18:45:27
不清楚你在问什么:
这个函数是这样工作的吗?
showIntAtBase 6 1025554775 = 245433110435请注意showIntAtBase的类型:
> :t showIntAtBase
showIntAtBase
:: (Show a, Integral a) => a -> (Int -> Char) -> a -> ShowS展开我们得到的ShowS类型别名:
> :t showIntAtBase
showIntAtBase
:: (Show a, Integral a) => a -> (Int -> Char) -> a -> String -> String所以你需要提供四个参数,而不是两个数字。例如,可以使用Data.Char.intToDigit将整数转换为字符,还可以对后缀字符串使用空字符串:
> import Data.Char (intToDigit)
> import Numeric (showIntAtBase)
> showIntAtBase 6 intToDigit 1025554775 ""
"245433110435"https://stackoverflow.com/questions/48507411
复制相似问题