Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Byte to Char ...

807605Aug 24 2007 — edited Aug 24 2007
Hi,

I have written an encryption function in PHP which at a certain point uses the built in chr() function to convert a byte back to a character. This works fine, however when I do the same thing in Java ( by casting the byte as a char ) I have problems.

It seems characters with ASCCI values greater than 128 are being displayed as the wrong characters and sometimes not at all ( they become ? ).

Some example output from the PHP ...

_____Byte______ASCCI_______Char

....-785314906..........166...................... �
....805139163...........219.......................�

Im assuming this is because the way PHP handles the bytes differs from java. Does anyone know how I can get my java representation of these bytes to work for conversion to characters ?

My java code goes like this ...
System.out.println((char)(byte) byteCode)
* byteCode is an integer variable containing values like those shown above.

Many thanks for any insight ...

Chris
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2007
Added on Aug 24 2007
2 comments
315 views