Mark said:
Good one. I was going to say that it's a wonder -1 is converted at all.
I would have expected an Exception.
I dunno what to do about the original poster's issue. Java has no
unsigned numbers, period. I assume he wants -1 to be converted to 255,
but a clean way to do this escapes me. I don't convert text all that
often.
if ( b < 0 )
b += 256;
... then convert b, might work...
If "correct" means "value of char is value of byte bit pattern treated
as unsigned binary" then the following works:
static char byteToChar(byte b){
return (char)(b & 0xff);
}
However, the mapping to 3f suggests that the bytes are being treated as
8 bit characters, rather than numbers, so the OP may mean something
entirely different by "correct".
Patricia