Java Hex Convert To fromHex(String hex)

Here you can find the source of fromHex(String hex)

Description

Converts a string of hexadecimal characters into a byte array.

License

Open Source License

Parameter

Parameter Description
hex the hex string

Return

the hex string decoded into a byte array

Declaration

private static byte[] fromHex(String hex) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from www  . j  ava  2s. c  om*/
     * Converts a string of hexadecimal characters into a byte array.
     *
     * @param hex
     *            the hex string
     * @return the hex string decoded into a byte array
     */
    private static byte[] fromHex(String hex) {
        byte[] binary = new byte[hex.length() / 2];
        for (int i = 0; i < binary.length; i++) {
            binary[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
        }
        return binary;
    }
}

Related

  1. fromHex(final String s)
  2. fromHex(final String string, final int offset, final int count)
  3. fromHex(String bytesString)
  4. fromHex(String encoded)
  5. fromHex(String hex)
  6. fromHex(String hex)
  7. fromHex(String hex)
  8. fromHex(String hex)
  9. fromHex(String hex)