Java Hex Calculate toHex(byte[] bytes)

Here you can find the source of toHex(byte[] bytes)

Description

to Hex

License

Open Source License

Declaration

public static String toHex(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final char[] hexChars = "0123456789ABCDEF".toCharArray();

    public static String toHex(byte[] bytes) {
        return toHex(bytes, 0, bytes.length);
    }//  www .  j a v a2 s .co  m

    public static String toHex(byte[] bytes, int offset, int length) {
        StringBuffer sb = new StringBuffer();
        if (bytes == null)
            return " null";
        if (offset >= length)
            return "invalid offset/length";
        for (int i = offset; i < (length - offset); i++) {
            sb.append(toHex(bytes[i]));
        }
        return sb.toString();
    }

    public static String toHex(byte val) {
        byte[] buff = new byte[2];
        buff[0] = (byte) hexChars[(val & 0xf0) >> 4];
        buff[1] = (byte) hexChars[val & 0xf];
        return new String(buff);
    }
}

Related

  1. toHex(byte[] b)
  2. toHex(byte[] b, int off, int len, String separator)
  3. toHEX(byte[] ba)
  4. toHex(byte[] buffer)
  5. toHex(byte[] buffer)
  6. toHex(byte[] bytes)
  7. toHex(byte[] bytes)
  8. toHex(byte[] bytes)
  9. toHex(byte[] bytes)