Skip to content

Instantly share code, notes, and snippets.

@kmizu
Forked from rirakkumya/hexToStr.scala
Created April 14, 2012 07:54
Show Gist options
  • Save kmizu/2382750 to your computer and use it in GitHub Desktop.
Save kmizu/2382750 to your computer and use it in GitHub Desktop.
16進文字列をAscii文字列に変換 (再帰を使わないバージョン)
def hexToStr(s:String):String = {
s.grouped(2).map{xx => Integer.parseInt(xx, 16).toChar}.mkString("")
}
val target = 'a' to 'z' mkString
val hexTarget = target map {"%02x" format _.toInt} mkString
assert(target == hexToStr(hexTarget))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment