Created
April 13, 2012 01:35
-
-
Save rirakkumya/2372705 to your computer and use it in GitHub Desktop.
16進文字列をAscii文字列に変換
This file contains hidden or 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
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