| Author |
Hex String to byte array
|
Titus Abraham
Ranch Hand
Joined: Jun 03, 2009
Posts: 36
|
|
I am puzzled,
I am trying to convert a hex string which i get from network but i am decoding it different everytime. I have no idea why. i am pasting the function which i am using .
Th Hex string is "827000000d5e"
any idea why ... I have been puzzling on it for 2 hours now..
any help appreciated..
best regards,
Titus
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Please Use Code Tags.
Some hints:
What if no.length() is odd? You're missing out one digit. Try the following:
That also ensures your string always has an even number of characters.
The "& 0x000000ff" part is unnecessary - the cast to byte cuts off anything over 0x000000ff anyway. But it doesn't hurt though.
Your second method can be removed, because the first method does the exact same thing - take a HEX string and create a byte[]. Why use two different methods? And the first one works (after the odd-length-fix) - I know because it's identical to my own HEX-string-to-byte method
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Titus Abraham
Ranch Hand
Joined: Jun 03, 2009
Posts: 36
|
|
|
Thank you...
|
 |
 |
|
|
subject: Hex String to byte array
|
|
|