
how to convert a hexadecimal into base 10 integer using haskell . I have written a code but its not working for large values , please help

On Wed, May 16, 2007 at 06:34:53PM +0530,
ashutosh dimri
how to convert a hexadecimal into base 10 integer using haskell . I have written a code but its not working for large values , please help
Not showing the code you wrote will not help. Please read the instructions first: http://www.haskell.org/haskellwiki/Homework_help

"ashutosh dimri"
how to convert a hexadecimal into base 10 integer using haskell . I have written a code but its not working for large values , please help
from http://pleac.sourceforge.net/pleac_haskell/numbers.html#AEN118 : -- "read" handles both octal and hexadecimal when prefixed with 0x or 0o -- here are versions adding the prefix and calling "read" hex s = read ("0x" ++ s) :: Integer oct s = read ("0o" ++ s) :: Integer -- hex "45" == 69 -- oct "45" == 37 -- hex "45foo" => Exception: Prelude.read: no parse -- calling explicitly readHex or readOct: hex = fst . head . Numeric.readHex oct = fst . head . Numeric.readOct

Pixel wrote:
from http://pleac.sourceforge.net/pleac_haskell/numbers.html#AEN118 : -- "read" handles both octal and hexadecimal when prefixed with 0x or 0o -- here are versions adding the prefix and calling "read" hex s = read ("0x" ++ s) :: Integer oct s = read ("0o" ++ s) :: Integer
-- hex "45" == 69 -- oct "45" == 37
I want to remark that Integer does not necessarily use decimal internally; rumour goes that it is binary. But whatever it is, "show" turns that into decimal, e.g., show (hex "45") gives "69" indeed.
participants (4)
-
Albert Y. C. Lai
-
ashutosh dimri
-
Pixel
-
Stephane Bortzmeyer