Java Hex Format formatHEX(byte[] btValue, int iOffset, int iLength)

Here you can find the source of formatHEX(byte[] btValue, int iOffset, int iLength)

Description

format HEX

License

Apache License

Declaration

public static String formatHEX(byte[] btValue, int iOffset, int iLength) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String formatHEX(byte[] btValue, int iOffset, int iLength) {
        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)
                h = (byte) ('0' + h);
            else// w w w.jav a2  s .c  o  m
                h = (byte) ('A' + h - 10);

            l = (byte) ((btValue[i] & 0x0F));
            if (l < 10)
                l = (byte) ('0' + l);
            else
                l = (byte) ('A' + l - 10);

            value.append((char) h);
            value.append((char) l);
        }
        return value.toString();
    }
}

Related

  1. formatAsRawHex(int bitStringLength, String hex)
  2. formatBytes2HexString(byte[] bytes, int offset, int length)
  3. formatByteToPaddedHex(int i, int l)
  4. formatColorInt2HexString(int c)
  5. formatGuidToDashedNotation(String hexValue)
  6. formatHex(double theG)
  7. formatHex(int value, int width)
  8. formatHex(Integer input)
  9. formatHexBytes(byte[] raw)