Android Byte Array to Hex Convert toHexString(byte[] keyData)

Here you can find the source of toHexString(byte[] keyData)

Description

to hex string

Parameter

Parameter Description
keyData a parameter

Declaration

private static String toHexString(byte[] keyData) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  www.  j a va  2s.  c o  m
     * to hex string
     * @param keyData
     * @return
     */
    private static String toHexString(byte[] keyData) {
        if (keyData == null) {
            return null;
        }
        int expectedStringLen = keyData.length * 2;
        StringBuilder sb = new StringBuilder(expectedStringLen);
        for (int i = 0; i < keyData.length; i++) {
            String hexStr = Integer.toString(keyData[i] & 0x00FF, 16);
            if (hexStr.length() == 1) {
                hexStr = "0" + hexStr;
            }
            sb.append(hexStr);
        }
        return sb.toString();

    }
}

Related

  1. toHexString(byte[] ba)
  2. toHexString(byte[] bytes)
  3. toHexString(byte[] bytes)
  4. toHexString(byte[] bytes)
  5. toHexString(byte[] bytes, int offset, int length)
  6. toHexStringArray(byte[] bytes)
  7. convertToHex(byte[] data)
  8. convertToHex(byte[] data)
  9. convertToHex(byte[] data)