Java Byte Array to Hex String bytesToHexString(byte[] data, int offset, int length)

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

Description

bytes To Hex String

License

Open Source License

Declaration

public static String bytesToHexString(byte[] data, int offset, int length) 

Method Source Code

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

public class Main {
    public static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
            'e', 'f' };

    public static String bytesToHexString(byte[] data, int offset, int length) {
        StringBuffer s = new StringBuffer();
        for (int i = offset; i < offset + length; i++) {
            int b = data[i] >= 0 ? data[i] : 0x0100 + data[i];
            s.append(HEX_DIGITS[b / 16]).append(HEX_DIGITS[b % 16]);
        }/*from w w w  .jav a 2 s .  c  om*/
        return s.toString();
    }
}

Related

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