• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

String conversion

 
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...
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!