I need to convert a Char to an Byte. I 开发者_JS百科belief this should be very simple but i don't find a nice solution.
0x7A.toChar => 'z'
'z'.???? => 0x7A
Edit:
I'm to tired... 'z'.toByte => 0x7A
scala> 'z'.toByte
res0: Byte = 122
scala> res0.toChar
res1: Char = z
Note that a Char
in Scala (and Java) is Unicode UTF-16 which means that it is 2 bytes. You might lose information!
精彩评论