File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hex String to byte array

 
Titus Abraham
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Titus Abraham
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic