Here you can find the source of toHex(byte[] dataBytes)
Parameter | Description |
---|---|
dataBytes | bytearray |
public static String toHex(byte[] dataBytes) throws NumberFormatException
//package com.java2s; import java.math.BigInteger; public class Main { /**/*from w w w.j ava 2s . com*/ * Encode a byte array to a hexadecimal string. * * @param dataBytes bytearray * @return hexadecimal string. */ public static String toHex(byte[] dataBytes) throws NumberFormatException { if (dataBytes == null || dataBytes.length == 0) { return ""; } byte[] dataPlus1Bytes = new byte[dataBytes.length + 1]; System.arraycopy(dataBytes, 0, dataPlus1Bytes, 1, dataBytes.length); dataPlus1Bytes[0] = 1; BigInteger dataPlus1BigInteger = new BigInteger(dataPlus1Bytes); return dataPlus1BigInteger.toString(16).substring(1); } }