Hi,
i've found a nice function which converts my byte array to a hex string.
static char[] hexChar = {
'0' , '1' , '2' , '3' ,
'4' , '5' , '6' , '7' ,
'8' , '9' , 'A' , 'B' ,
'C' , 'D' , 'E' , 'F'
};
public static String toHexString ( byte[] b ) {
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] ); // fill left with zero bits
// look up low nibble char
sb.append( hexChar [b[i] & 0x0f] );
}
return sb.toString();
}
It's working fine, but i need the conversion in the other direction. It should be very easy, but i didn't get it.
I first tried to use simply
byte[] bArray = hexStr.getBytes();
but it seems to be something different.
But why is it different?