Here you can find the source of fromHexString(String hexString)
Parameter | Description |
---|---|
hexString | the hex string to convert |
public static byte[] fromHexString(String hexString)
//package com.java2s; /*/*from w w w . j a va 2 s.c o m*/ * Copyright 2009 Jagornet Technologies, LLC. All Rights Reserved. * * This software is the proprietary information of Jagornet Technologies, LLC. * Use is subject to license terms. * */ public class Main { /** * From hex string. * * @param hexString the hex string to convert * * @return the byte[] the converted byte array */ public static byte[] fromHexString(String hexString) { if (hexString != null) { int strlen = hexString.length(); int blen = strlen / 2 + strlen % 2; byte[] barray = new byte[blen]; int i = 0; int j = 0; if (strlen % 2 > 0) { // if odd number of characters, prepend a zero hexString = "0" + hexString; } while (i < hexString.length()) { int hex = Integer.parseInt(hexString.substring(i, i + 2), 16); barray[j] = (byte) hex; i += 2; j++; } return barray; } return null; } }