Skip to content

Instantly share code, notes, and snippets.

@rirakkumya
Created April 13, 2012 01:35
Show Gist options
  • Save rirakkumya/2372705 to your computer and use it in GitHub Desktop.
Save rirakkumya/2372705 to your computer and use it in GitHub Desktop.
16進文字列をAscii文字列に変換
import scala.annotation.tailrec
def hexToStr(s:String):String = {
@tailrec def r(target:String,result:String):String = {
target splitAt 2 match {
case (xx,xs) if !xx.isEmpty => r(xs,result + Integer.parseInt(xx,16).toChar)
case _ => result
}
}
r(s,"")
}
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