I am reading an array of bytes. I want to translate each hexadecimal number into it's ASCII value. How can I do this?
The array is of type byte, because I am using RandomAccessFile to read the input from a source file. When I try to call byteVariable.toString() method, I get an error "cannot dereference" at compile time. I suppose this error would not occur if it was of type Byte, but when I change the type of my array variable to Byte, I get an error from RandomAccessFile class, it seems like it wants type byte.
I am new to Java so I am not copmletely sure what is going on.
First off, you must've overlooked our naming policy when you sign up. We need to see real first and last names. You can fix it here. Thanks, pardner!
Now, as to your question: I suppose the right answer depends on exactly what you want to do with the "ASCII value." I'm going to guess "Print it as a number from 0 to 255". In that case, using the bitwise "and" operator and an appropriate bitmask is the right way to convert the byte to a non-negative integer:
prints "219". [ June 03, 2004: Message edited by: Ernest Friedman-Hill ]