开发者

Convert String to Byte

开发者 https://www.devze.com 2023-01-09 09:44 出处:网络
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.

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消