• Post Reply Bookmark Topic Watch Topic
  • New Topic

String conversion  RSS feed

 
Martin Phee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to convert a string in to parts like this.

Take "MARTY"
The hex value is 4D 41 52 54 59

I need to convert it then by taking each byte, 4D, and writing it as two bytes that represent the ascii character 4 and D.

34 44

I've already written a some logic to do it:
char high = hex.substring(0).toUpperCase().toCharArray()[0];
String part_one = Integer.toHexString( new Integer(high).intValue() );

char low = hex.substring(1).toUpperCase().toCharArray()[0];
String part_two= Integer.toHexString( new Integer(low).intValue() );

But this seems like a lot of overhead since I'm going to need to convert this data quickly and I'm probably going to have a lot of it.

Just assume that the data will be in either a byte or char array. Even a string...
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!