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.decode() for hex values greater than 0x7F?

807591May 8 2008 — edited May 8 2008
I have a function that takes a string of "hex" values as an argument (e.g., "0x05","0x21","0xF2"), and converts them to actual bytes to manipulate them.
byte[] data = new byte[255];
String[] s = args[0].split(",");

for (int i = 0; i < s.length; i++) {
    data[i] = Byte.decode(s);
}
This works great up to hex value 0x7F (integer value 127), however bombs on larger values, I believe because Bytes are signed(?) in Java.

There must be a workaround--any suggestions?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 5 2008
Added on May 8 2008
2 comments
812 views