Android Byte Array to Hex Convert toHexString(byte[] bytes, int offset, int length)

Here you can find the source of toHexString(byte[] bytes, int offset, int length)

Description

to Hex String

License

Apache License

Declaration

public static String toHexString(byte[] bytes, int offset, int length) 

Method Source Code

//package com.java2s;
/**/*from  w  w  w  . j av  a  2s . co m*/
 * Source obtained from crypto-gwt. Apache 2 License.
 * https://code.google.com/p/crypto-gwt/source/browse/crypto-gwt/src/main/java/com/googlecode/
 * cryptogwt/util/ByteArrayUtils.java
 */

public class Main {
    public static String toHexString(byte[] bytes) {
        StringBuilder builder = new StringBuilder();
        for (byte b : bytes) {
            builder.append(Integer.toHexString((b >> 4) & 0xf));
            builder.append(Integer.toHexString(b & 0xf));
        }
        return builder.toString();
    }

    public static String toHexString(byte[] bytes, int offset, int length) {
        return toHexString(copyOfRange(bytes, offset, length));
    }

    public static byte[] copyOfRange(byte[] bytes, int offset, int len) {
        byte[] result = new byte[len];
        System.arraycopy(bytes, offset, result, 0, len);
        return result;
    }
}

Related

  1. toHex(byte[] dataBytes)
  2. toHexString(byte[] ba)
  3. toHexString(byte[] bytes)
  4. toHexString(byte[] bytes)
  5. toHexString(byte[] bytes)
  6. toHexString(byte[] keyData)
  7. toHexStringArray(byte[] bytes)
  8. convertToHex(byte[] data)
  9. convertToHex(byte[] data)