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

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

Description

to Hex String

Declaration

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

Method Source Code

//package com.java2s;

public class Main {
    public static String toHexString(byte[] bytes) {
        return toHexString(bytes, bytes.length);
    }//from   w  w w .  jav a2s.  c  om

    public static String toHexString(byte[] bytes, int numBytes) {
        if (bytes == null)
            return "";
        if (bytes.length == 0)
            return "";
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < Math.min(numBytes, bytes.length); i++) {
            String h = Integer.toHexString(0xFF & bytes[i]);
            if (h.length() < 2)
                result.append('0');
            result.append(h);
        }
        return result.toString();
    }
}

Related

  1. bytesToHexString(byte[] src)
  2. bytesToHexString(byte[] values)
  3. bytesAsHexString(byte[] bytes, int maxShowBytes)
  4. toHexString(byte[] bytes)
  5. toHexString(byte[] bytes)
  6. toHexString(byte[] bytes, int offset, int length)
  7. toHexString(byte[] data)
  8. toHexString(byte[] data, int offset, int length)
  9. toHexStringArray(byte[] data, int offset, int length)