private static char [ ] encode ( final byte [ ] data , final char [ ] toDigits ) { final int l = data . length ; final char [ ] out = new char [ l << 1 ] ; // two characters form the hex value. for ( int i = 0 , j = 0 ; i < l ; i ++ ) { out [ j ++ ] = toDigits [ ( 0xF0 & data [ i ] ) >>> 4 ] ; out [ j ++ ] = toDigits [ 0x0F & data [ i ] ] ; } return out ; }
Converts an array of bytes into an array of characters representing the hexadecimal 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 .