private static String convertToHex ( byte [ ] data ) { final StringBuffer buffer = new StringBuffer ( ) ; for ( int i = 0 ; i < data . length ; i ++ ) { int halfByte = ( data [ i ] >>> 4 ) & 0x0F ; int twoHalves = 0 ; do { if ( ( 0 <= halfByte ) && ( halfByte <= 9 ) ) { buffer . append ( ( char ) ( ' ' + halfByte ) ) ; } else { buffer . append ( ( char ) ( ' ' + ( halfByte - 10 ) ) ) ; } halfByte = data [ i ] & 0x0F ; } while ( twoHalves ++ < 1 ) ; } return buffer . toString ( ) ; }
Converts an array of bytes to its hexadecimal equivalent