Java Byte Array to Hex String bytesToHexString(byte[] data, int fromIndex, int toIndex)

Here you can find the source of bytesToHexString(byte[] data, int fromIndex, int toIndex)

Description

bytes To Hex String

License

Open Source License

Declaration

public static String bytesToHexString(byte[] data, int fromIndex, int toIndex) 

Method Source Code

//package com.java2s;

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

    public static String bytesToHexString(byte[] data) {
        return bytesToHexString(data, 0, data.length);
    }/*from w ww  . j  av  a  2 s  .co m*/

    public static String bytesToHexString(byte[] data, int fromIndex, int toIndex) {
        StringBuilder sb = new StringBuilder();
        for (int i = fromIndex; i < toIndex; i++) {
            sb.append(hex[(data[i] >> 4) & 0xf]);
            sb.append(hex[data[i] & 0xf]);
        }
        return sb.toString();
    }
}

Related

  1. bytesToHexString(byte[] bytes)
  2. bytesToHexString(byte[] bytes)
  3. bytesToHexString(byte[] bytes)
  4. bytesToHexString(byte[] data)
  5. bytesToHexString(byte[] data)
  6. bytesToHexString(byte[] data, int offset, int length)
  7. bytesToHexString(byte[] hasher)
  8. bytesToHexString(byte[] in, int length)
  9. bytesToHexString(byte[] input)