Java Hex Calculate toHexString(byte input[])

Here you can find the source of toHexString(byte input[])

Description

to Hex String

License

Apache License

Declaration

public static String toHexString(byte input[]) 

Method Source Code

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

public class Main {
    public static String toHexString(byte input[]) {
        return toHexString(input, input.length);
    }//from   w w  w  . j  ava 2s .  co  m

    public static String toHexString(byte input[], int limit) {
        int i = 0;
        if (input == null || input.length <= 0)
            return null;

        char lookup[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

        char[] result = new char[(input.length < limit ? input.length : limit) * 2];

        while (i < limit && i < input.length) {
            result[2 * i] = lookup[(input[i] >> 4) & 0x0F];
            result[2 * i + 1] = lookup[(input[i] & 0x0F)];
            i++;
        }
        return String.valueOf(result);
    }
}

Related

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