private static String getHexString ( byte [ ] bytes ) { // If null byte array given, return null if ( bytes == null ) return null ; // Create string builder for holding the hex representation, // pre-calculating the exact length StringBuilder hex = new StringBuilder ( 2 * bytes . length ) ; // Convert each byte into a pair of hex digits for ( byte b : bytes ) { hex . append ( HEX_CHARS [ ( b & 0xF0 ) >> 4 ] ) . append ( HEX_CHARS [ b & 0x0F ] ) ; } // Return the string produced return hex . toString ( ) ; }
Produces a String containing the bytes provided in hexadecimal notation .