I am just asking a quick simple question here. I’m trying to code poker card rankings into 4 digit binary code (exp. 2 is 0010, 7 is 0111)(ignoring the suits for now). Then decoding and print it out.
To my knowledge the best way of changing a Int into a String is by using the function show. However, using it on this situation it drops all the zeros that is in front of the 1 (exp. show 0011 returns “11”, show 0001 returns “1”). How do I keep the zeros?
Thanks
Because 0001 is a number, and not a character string. The 0001 read syntax is converted into an integer object, and when you print that integer object, it prints in decimal as 1.
1 is the successor to 0. There are no zeros in 1. 🙂
To print 1 as 0001, try the prelude that provides printf:
E.g
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Text-Printf.html