Hi guy,
I need to store an image as a String, this would not be as hard if the String didnt need to be in "hex" format, i can convert the image to byte array. and i have this code to convert it to a String, but i am not sure how to convert it back to a byte array.. the same byte array.
/**
*Takes in a byte array and converts in to a stirng array of hex
*/
private static String toHexString( byte[] b )
{
// table to convert a nibble to a hex char.
char[] hexChar = {
'0' , '1' , '2' , '3' ,
'4' , '5' , '6' , '7' ,
'8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f'};
StringBuffer sb = new StringBuffer( b.length * 2 );
for ( int i=0; i<b.length; i++ )
{
// look up high nibble char
sb.append( hexChar [( b[i] & 0xf0 ) >>> 4] );
// look up low nibble char
sb.append( hexChar [b[i] & 0x0f] );
}
return sb.toString();
}
Thanks please can you explain how to reconvert it back to the byte array, or if that is not going to work some help with writting a way that this can be done.
Many thanks
David