Java Hex Calculate toHexString(byte a)

Here you can find the source of toHexString(byte a)

Description

to Hex String

License

Open Source License

Declaration

public static final String toHexString(byte a) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

public class Main {
    /** The hexadecimal digits "0" through "f". */
    private static char[] NIBBLE = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
            'f', };

    public static final String toHexString(byte a) {
        StringBuffer sb = new StringBuffer(2);
        sb.append(NIBBLE[(a >>> 4) & 0xf]);
        sb.append(NIBBLE[a & 0xf]);/*  w w  w .  j av  a2s. c  o  m*/

        return sb.toString();
    }

    /**
     * Convert a byte array to a string of hexadecimal digits.
     */
    public static final String toHexString(byte[] buf) {
        StringBuffer sb = new StringBuffer(buf.length * 2);

        for (int i = 0; i < buf.length; i++) {
            sb.append(NIBBLE[(buf[i] >>> 4) & 15]);
            sb.append(NIBBLE[buf[i] & 15]);
        }

        return sb.toString();
    }
}

Related

  1. toHexShortString(byte[] bytes)
  2. toHexStr(byte b[])
  3. toHexStr(byte[] b)
  4. toHexStr(byte[] binary)
  5. toHexStream(byte[] bytes, String delimiter, boolean prefixEachValue, boolean upperCase)
  6. toHexString(byte abyte0[], boolean spaceFlag)
  7. toHexString(byte b)
  8. toHexString(byte b)
  9. toHexString(byte b)