Java Hex Calculate toHexString(byte value)

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

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(byte value) 

Method Source Code

//package com.java2s;

public class Main {
    final static byte[] digits = { (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5',
            (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd',
            (byte) 'e', (byte) 'f' };

    public static String toHexString(byte value) {
        return toUnsignedString(value & 0xFF, 4);
    }/*from  www  .j a v  a 2s. c om*/

    static String toUnsignedString(int i, int shift) {
        byte[] buf = new byte[] { (byte) '0', (byte) '0' };
        int charPos = 2;
        int radix = 1 << shift;
        int mask = radix - 1;
        do {
            buf[--charPos] = digits[i & mask];
            i >>>= shift;
        } while (i != 0);

        return new String(buf);
    }
}

Related

  1. toHexString(byte bytes[])
  2. toHexString(byte bytes[])
  3. toHexString(byte data[])
  4. toHexString(byte input[])
  5. toHexString(byte n)
  6. toHexString(byte value)
  7. toHexString(byte[] arr)
  8. toHexString(byte[] array)
  9. toHexString(byte[] array)