Java Hex Calculate toHex(byte[] b, int off, int len, String separator)

Here you can find the source of toHex(byte[] b, int off, int len, String separator)

Description

to Hex

License

Open Source License

Declaration

public static String toHex(byte[] b, int off, int len, String separator) 

Method Source Code

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

public class Main {
    public static String toHex(int b) {
        String result = String.format("%02X", b & 0xFF);
        return result;
    }//from www  .  j a  v  a 2 s .  c o  m

    public static String toHex(byte b) {
        String result = String.format("%02X", b);
        return result;
    }

    public static String toHex(byte[] b) {
        return toHex(b, 0, b.length);
    }

    public static String toHex(byte[] b, int off, int len) {
        return toHex(b, off, len, "");
    }

    public static String toHex(byte[] b, int off, int len, String separator) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < b.length && i < len; i++) {
            result.append(toHex(b[i]));
            if (i != b.length - 1)
                result.append(separator);
        }
        return result.toString();
    }
}

Related

  1. toHex(byte[] b)
  2. toHex(byte[] b)
  3. toHex(byte[] b)
  4. toHex(byte[] b)
  5. toHex(byte[] b)
  6. toHEX(byte[] ba)
  7. toHex(byte[] buffer)
  8. toHex(byte[] buffer)
  9. toHex(byte[] bytes)