Last active
December 21, 2015 11:18
-
-
Save bmarcot/db2014a6e5e7e3854052 to your computer and use it in GitHub Desktop.
atoi() for any base.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hexToInt(s: String): Int = { | |
s.toList.map("0123456789abcdef".indexOf(_)).reduceLeft(_ * 16 + _) | |
} | |
def baseToInt(s: String, base: String): Int = { | |
s.toList.map(base.indexOf(_)).reduceLeft(_ * base.length + _) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment