Java Hex Convert To fromHexString(final String str)

Here you can find the source of fromHexString(final String str)

Description

from Hex String

License

Apache License

Declaration

public static byte[] fromHexString(final String str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static final String ERROR_INPUT_STRING_NUM_CHARS = "Input string must contain an even number of characters";
    private static final String STR_HEX_PREFIX = "0x";

    public static byte[] fromHexString(final String str) {
        if ((str.length() % 2) != 0)
            throw new IllegalArgumentException(ERROR_INPUT_STRING_NUM_CHARS);

        byte[] result = new byte[str.length() / 2];
        for (int i = 0; i < str.length() / 2; i++) {
            result[i] = (Integer.decode(STR_HEX_PREFIX + str.substring(i * 2, (i + 1) * 2))).byteValue();
        }/*from  ww w  . j  av a 2  s. com*/
        return result;
    }
}

Related

  1. fromHexStr(final String data)
  2. fromHexString(byte abyte0[], int i)
  3. fromHexString(final String hexaString)
  4. fromHexString(final String hexString)
  5. fromHexString(final String s)
  6. fromHexString(String encoded)
  7. fromHexString(String encoded)
  8. fromHexString(String hex)
  9. fromHexString(String hex)