How to convert Char to Int in Haskell?
Solution 1
You can use the ord
function to convert a character to its integer (ordinal) representation.
chr
goes the other direction.
> ord '\x2'
=> 2
> chr 97
=> 'a'
> ord (chr 42)
=> 42
Solution 2
You can use fromEnum or Data.Char.ord.
Related videos on Youtube
Usama Abdulrehman
Web Log data Processing Quick Prototyping for Processing Large Data-sets Installation & Configuration of Windows Server, SUSE Linux Enterprise Server, Ubuntu, CentOS Operating Systems on Physical Servers and Virtual Servers VMware & Oracle VM Virtual Box Deployment of Apache Hadoop, Sqoop, Hive, MySQL, Pig Build your systems using Apache Software Foundation Tools on top of most reliable and secure Linux Ecosystem. SAP Digital Badge Download in PDF Step by Step https://www.youtube.com/watch?v=UWH_HLtL9dI
Updated on July 09, 2022Comments
-
Usama Abdulrehman almost 2 years
I need to convert a
Char
to anInt
in Haskell? For example:a = '\x2' -- a == 2 -- type of a should be Char b = charToInt a -- b == 2 -- type of b should be Int
How can I achieve this?
-
Thomas M. DuBuisson about 13 yearsDiscover and use hoogle.
-
-
newacct about 13 yearsjust to add, you have to
import Char
orimport Data.Char
in order to use those