Here you can find the source of fromHex(String dataString)
Parameter | Description |
---|---|
dataString | a hexadecimal string (The string length must be even.) |
public static byte[] fromHex(String dataString)
//package com.java2s; import java.math.BigInteger; public class Main { /**//w w w.jav a2 s. c o m * Decode a hexadecimal string to a bytearray. * * @param dataString a hexadecimal string (The string length must be even.) * @return Decoded bytearray (if dataString == "" then return null.) */ public static byte[] fromHex(String dataString) { if (dataString.equals("")) { return null; } BigInteger dataPlus1BigInteger = new BigInteger("10" + dataString, 16); byte[] dataPlus1Bytes = dataPlus1BigInteger.toByteArray(); byte[] dataBytes = new byte[dataPlus1Bytes.length - 1]; System.arraycopy(dataPlus1Bytes, 1, dataBytes, 0, dataBytes.length); return dataBytes; } }