[Haskell-cafe] haskell quiry

ashutosh dimri adimri.iitkgp at gmail.com
Thu May 17 05:49:24 EDT 2007


 I have written a code to convert hexadecimal numbers into base 10 number
but its working only for 32 bits and I  need it to work upto 160 bits , code
is given below. please help.

--its a program to convert hexadecimal numbers into base 10 numbers

import Char

-- the function "func" takes a list of strings in hexadecimal and convert
-- it to a list of corresponding numbers in decimal format
-- func "eefba12" = [14,14,15,11,10,1,2]

func [] = []
func (x:xs)
    |(ord x > 57) = ((ord x)-87):func xs
    |otherwise  =  ((ord x)-48):func xs

-- (mul.func) function takes a hexadecimal number and convert it to base 10
but its working only for 32 bits
-- whereas haskell supports calculations much higher than 32 bits.....
-- mul.func $ "ee" = 238
-- mul.func $ "e23e" = 57918

mul xs = mul1 xs ((length xs)-1)
mul1 (x:xs) 0 = x
mul1 (x:xs) n = (x*16^n)+ mul1 xs (n-1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070517/8ee7ce79/attachment.htm


More information about the Haskell-Cafe mailing list