public static char [ ] encodeHex ( byte [ ] data ) { int l = data . length ; char [ ] out = new char [ l << 1 ] ; // two characters form the hex value. for ( int i = 0 , j = 0 ; i < l ; i ++ ) { out [ j ++ ] = DIGITS [ ( 0xF0 & data [ i ] ) >>> 4 ] ; out [ j ++ ] = DIGITS [ 0x0F & data [ i ] ] ; } return out ; }
Converts an array of bytes into an array of characters representing the hexidecimal values of each byte in order . The returned array will be double the length of the passed array as it takes two characters to represent any given byte .