Java Utililty Methods Hex Format

List of utility methods to do Hex Format

Description

The list of methods to do Hex Format are organized into topic(s).

Method

StringformatGuidToDashedNotation(String hexValue)
Returns dashed GUID notation formatted from simple hex-encoded binary.
if (hexValue == null) {
    return null;
StringBuilder sb = new StringBuilder();
sb.append(hexValue.substring(6, 8));
sb.append(hexValue.substring(4, 6));
sb.append(hexValue.substring(2, 4));
sb.append(hexValue.substring(0, 2));
...
StringformatHEX(byte[] btValue, int iOffset, int iLength)
format HEX
int iLastOffset = iOffset + iLength;
if (btValue.length < iLastOffset || iLength < 1)
    return "";
StringBuffer value = new StringBuffer();
for (int i = iOffset; i < iLastOffset; i++) {
    byte l, h;
    h = (byte) ((btValue[i] & 0xF0) >>> 4);
    if (h < 10)
...
StringformatHex(double theG)
format Hex
int value = (int) (theG * 256);
String retVal = Integer.toHexString(value);
int len = retVal.length();
switch (len) {
case 0:
    retVal = "00";
    break;
case 1:
...
StringformatHex(int value, int width)
format Hex
StringBuilder sb = new StringBuilder();
sb.append(Integer.toHexString(value));
if (width > sb.length()) {
    sb.insert(0, ZEROS8, 0, width - sb.length());
return sb.toString();
StringformatHex(Integer input)
format Hex
return "0x" + Integer.toHexString(input);
StringformatHexBytes(byte[] raw)
Format a raw array of binary bytes as a hexadecimal string.
StringBuffer buffer;
final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
int i;
int value;
buffer = new StringBuffer(raw.length * 2);
for (i = 0; i < raw.length; i++) {
    value = raw[i];
    buffer.append(hexDigits[(value >> 4) & 0x0F]);
...
voidformatHexInt(final StringBuilder dst, final int p, int w)
format Hex Int
int o = p + 7;
while (o >= p && w != 0) {
    dst.setCharAt(o--, hexchar[w & 0xf]);
    w >>>= 4;
while (o >= p) {
    dst.setCharAt(o--, '0');
StringformatHexReversed(String original, int length)
format Hex Reversed
String newString = original;
for (int i = original.length(); i < length; i++) {
    newString += "0";
return newString;
StringformatHexStr(int width, String hexStr)
format Hex Str
if (hexStr.length() >= width) {
    return hexStr.substring(hexStr.length() - width);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < width - hexStr.length(); i++) {
    sb.append("0");
sb.append(hexStr);
...
StringformatHexString(final String input, final int charsPerLine)
format Hex String
StringBuilder buf = new StringBuilder(input.length() * 2);
int index = 0;
while ((index + charsPerLine) < input.length()) {
    String str = input.substring(index, index + charsPerLine);
    buf.append(spaceHexString(str));
    buf.append("\n");
    index += charsPerLine;
String str = input.substring(index);
buf.append(spaceHexString(str));
return (buf.toString());