tags:

views:

87

answers:

1

Hi

I need to convert a Char to an Byte. I 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

+4  A: 
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!

olle kullberg
Ah that's the difference between Byte and Char ;)(I have to communicate with an old system => so i need 8-Bit Char...)
nuriaion