Skip to content

Instantly share code, notes, and snippets.

@bmarcot
Last active December 21, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmarcot/db2014a6e5e7e3854052 to your computer and use it in GitHub Desktop.
Save bmarcot/db2014a6e5e7e3854052 to your computer and use it in GitHub Desktop.
atoi() for any base.
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