List of utility methods to do Byte Array to Hex String
String | bytesToHexString(final byte[] bytes) Convert a byte array to an hexadecimal string. StringBuffer hexString = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { int hex = (0xff & bytes[i]); String tmp = Integer.toHexString(hex); tmp = (tmp.length() < 2) ? "0" + tmp : tmp; hexString.append(tmp); return hexString.toString().toUpperCase(); ... |
String | bytesToHexString(final byte[] bytes) Convert a byte array into a hex string. final StringBuilder builder = new StringBuilder(bytes.length * 2); for (byte b : bytes) { builder.append(table[b >> 4 & 0x0f]).append(table[b & 0x0f]); return builder.toString(); |
String | bytesToHexString(final byte[] bytes) bytes To Hex String StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { byte b = bytes[i]; String hex = Integer.toHexString(b); if (hex.length() == 1) { hex = "0" + hex; if (hex.length() > 2) { ... |
String | bytesToHexString(final byte[] bytes, int start, int end) Returns the string representation of the given bytes . if (bytes == null || bytes.length == 0) { return EMPTY_STRING; final StringBuilder builder = new StringBuilder((end - start) << 1); for (int index = start; index < end; index++) { builder.append(String.format("%02x", bytes[index])); return builder.toString(); ... |
String | bytesToHexString(final byte[] data) Convert a byte array into a String hex representation. final char[] chars = new char[2 * data.length]; for (int i = 0; i < data.length; i++) { final byte b = data[i]; chars[2 * i] = toHexDigit((b >> 4) & 0xF); chars[2 * i + 1] = toHexDigit(b & 0xF); return new String(chars); |
String | bytesToHexStringLine(byte[] bs, int lineLength) bytes To Hex String Line if (bs == null || bs.length == 0) { return ""; StringBuffer str = new StringBuffer(bs.length * 4); for (int i = 0; i < bs.length; i++) { str.append(hex[(bs[i] >> 4) & 0x0f]); str.append(hex[bs[i] & 0x0f]); if (i > 0 && i % lineLength == lineLength - 1) { ... |
String | bytesToHexStringWithSpace(byte[] bytes) bytes To Hex String With Space char[] hexChars = new char[2 + ((bytes.length - 1) * 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]; if (hexChars.length < (j * 3 + 2)) { hexChars[j * 3 + 2] = ' '; return new String(hexChars); |