### Question:
Hex { public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 3]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 3] = hexArray[v >>> 4]; hexChars[j * 3 + 1] = hexArray[v & 0x0F]; hexChars[j * 3 + 2] = ' '; } return new String(hexChars, 0, hexChars.length - 1); }  static String bytesToHex(byte[] bytes); static String bytesToHex(byte[] bytes, int offset, int length);  }### Answer:
@Test public void testEightAs() throws Exception { final byte[] EightA = "AAAAAAAA".getBytes(Charset.defaultCharset()); String s = Hex.bytesToHex(EightA); Assert.assertEquals("41 41 41 41 41 41 41 41", s); }
@Test public void testAllValues() throws Exception { final byte[] all = new byte[256]; final char[] val = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; for (int i = 0; i < 256; i++) { all[i] = (byte) i; } String s = Hex.bytesToHex(all); int countSpace = 0; for (int i = 0; i < s.length(); i++) { countSpace += (s.charAt(i) == ' ' ) ? 1 : 0; } Assert.assertEquals(255, countSpace); Scanner scanner = new Scanner(s); for (char aVal : val) { for (char aVal1 : val) { Assert.assertEquals(String.format("%c%c", aVal, aVal1), scanner.next()); } } }