/** * Converts the parameter to a hex value. * * @param value The value to convert * @return The result right padded with 0 */ public static String toHex(short value) { StringBuilder sb = new StringBuilder(4); writeHex(sb, value & 0xFFFF, 4, ""); return sb.toString(); }
/** * @return string of 8 (zero padded) uppercase hex chars and prefixed with '0x' */ public static String intToHex(int value) { StringBuilder sb = new StringBuilder(10); writeHex(sb, value & 0xFFFFFFFFL, 8, "0x"); return sb.toString(); }
/** * Converts the parameter to a hex value. * * @param value The value to convert * @return The result right padded with 0 */ public static String toHex(long value) { StringBuilder sb = new StringBuilder(16); writeHex(sb, value, 16, ""); return sb.toString(); }
/** * @return string of 4 (zero padded) uppercase hex chars and prefixed with '0x' */ public static String shortToHex(int value) { StringBuilder sb = new StringBuilder(6); writeHex(sb, value & 0xFFFFL, 4, "0x"); return sb.toString(); }
/** * Converts the parameter to a hex value. * * @param value The value to convert * @return The result right padded with 0 */ public static String toHex(byte value) { StringBuilder sb = new StringBuilder(2); writeHex(sb, value & 0xFF, 2, ""); return sb.toString(); }
/** * Converts the parameter to a hex value. * * @param value The value to convert * @return The result right padded with 0 */ public static String toHex(int value) { StringBuilder sb = new StringBuilder(8); writeHex(sb, value & 0xFFFFFFFFL, 8, ""); return sb.toString(); }
/** * @return string of 16 (zero padded) uppercase hex chars and prefixed with '0x' */ public static String longToHex(long value) { StringBuilder sb = new StringBuilder(18); writeHex(sb, value, 16, "0x"); return sb.toString(); }
/** * @return string of 2 (zero padded) uppercase hex chars and prefixed with '0x' */ public static String byteToHex(int value) { StringBuilder sb = new StringBuilder(4); writeHex(sb, value & 0xFFL, 2, "0x"); return sb.toString(); }
/** * <p>Converts the parameter to a hex value breaking the results into * lines.</p> * * @param value The value to convert * @param bytesPerLine The maximum number of bytes per line. The next byte * will be written to a new line * @return A String representing the array of bytes */ public static String toHex(final byte[] value, final int bytesPerLine) { if (value.length == 0) { return ": 0"; } final int digits = (int) Math.round(Math.log(value.length) / Math.log(10) + 0.5); StringBuilder retVal = new StringBuilder(); writeHex(retVal, 0, digits, ""); retVal.append(": "); for(int x=0, i=-1; x < value.length; x++) { if (++i == bytesPerLine) { retVal.append('\n'); writeHex(retVal, x, digits, ""); retVal.append(": "); i = 0; } else if (x>0) { retVal.append(", "); } retVal.append(toHex(value[x])); } return retVal.toString(); }
/** * Converts the parameter to a hex value. * * @param value The value to convert * @return The result right padded with 0 */ public static String toHex(long value) { StringBuilder sb = new StringBuilder(16); writeHex(sb, value, 16, ""); return sb.toString(); }
/** * @return string of 16 (zero padded) uppercase hex chars and prefixed with '0x' */ public static String longToHex(long value) { StringBuilder sb = new StringBuilder(18); writeHex(sb, value, 16, "0x"); return sb.toString(); }
/** * Converts the parameter to a hex value. * * @param value The value to convert * @return The result right padded with 0 */ public static String toHex(int value) { StringBuilder sb = new StringBuilder(8); writeHex(sb, value & 0xFFFFFFFFL, 8, ""); return sb.toString(); }
/** * @return string of 2 (zero padded) uppercase hex chars and prefixed with '0x' */ public static String byteToHex(int value) { StringBuilder sb = new StringBuilder(4); writeHex(sb, value & 0xFFL, 2, "0x"); return sb.toString(); }
/** * Converts the parameter to a hex value. * * @param value The value to convert * @return The result right padded with 0 */ public static String toHex(short value) { StringBuilder sb = new StringBuilder(4); writeHex(sb, value & 0xFFFF, 4, ""); return sb.toString(); }
/** * Converts the parameter to a hex value. * * @param value The value to convert * @return The result right padded with 0 */ public static String toHex(byte value) { StringBuilder sb = new StringBuilder(2); writeHex(sb, value & 0xFF, 2, ""); return sb.toString(); }
/** * @return string of 8 (zero padded) uppercase hex chars and prefixed with '0x' */ public static String intToHex(int value) { StringBuilder sb = new StringBuilder(10); writeHex(sb, value & 0xFFFFFFFFL, 8, "0x"); return sb.toString(); }
/** * @return string of 4 (zero padded) uppercase hex chars and prefixed with '0x' */ public static String shortToHex(int value) { StringBuilder sb = new StringBuilder(6); writeHex(sb, value & 0xFFFFL, 4, "0x"); return sb.toString(); }
/** * <p>Converts the parameter to a hex value breaking the results into * lines.</p> * * @param value The value to convert * @param bytesPerLine The maximum number of bytes per line. The next byte * will be written to a new line * @return A String representing the array of bytes */ public static String toHex(final byte[] value, final int bytesPerLine) { if (value.length == 0) { return ": 0"; } final int digits = (int) Math.round(Math.log(value.length) / Math.log(10) + 0.5); StringBuilder retVal = new StringBuilder(); writeHex(retVal, 0, digits, ""); retVal.append(": "); for(int x=0, i=-1; x < value.length; x++) { if (++i == bytesPerLine) { retVal.append('\n'); writeHex(retVal, x, digits, ""); retVal.append(": "); i = 0; } else if (x>0) { retVal.append(", "); } retVal.append(toHex(value[x])); } return retVal.toString(); }