Java Hex Convert To fromHexString(String hexString)

Here you can find the source of fromHexString(String hexString)

Description

From hex string.

License

Open Source License

Parameter

Parameter Description
hexString the hex string to convert

Return

the byte[] the converted byte array

Declaration

public static byte[] fromHexString(String hexString) 

Method Source Code

//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;
    }
}

Related

  1. fromHexString(final String str)
  2. fromHexString(String encoded)
  3. fromHexString(String encoded)
  4. fromHexString(String hex)
  5. fromHexString(String hex)
  6. fromHexString(String hexString)
  7. fromHexString(String hexString)
  8. fromHexString(String hexString)
  9. fromHexString(String in)