Android Hex String to Byte Array Convert fromHex(String hex)

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

Description

Get the string based on the hex format

License

Open Source License

Parameter

Parameter Description
hex the Hex format of the string

Return

the normal string.

Declaration

public static String fromHex(String hex) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w w w  . j a  v  a  2s . c  o m
     * Get the string based on the hex format
     * @param hex the Hex format of the string
     * @return the normal string.
     */
    public static String fromHex(String hex) {
        return new String(toByte(hex));
    }

    /**
     * Retrieve the bytes data
     * @param hexString the source string
     * @return the source string's byte data.
     */
    public static byte[] toByte(String hexString) {
        int len = hexString.length() / 2;
        byte[] result = new byte[len];
        for (int i = 0; i < len; i++)
            result[i] = Integer.valueOf(
                    hexString.substring(2 * i, 2 * i + 2), 16).byteValue();
        return result;
    }
}

Related

  1. hexStringToBytes(String hexString)
  2. toByte(String hexString)
  3. toByte(String hexString)
  4. hex2byte(String inputString)
  5. fromHex(String hex)
  6. hexToBytes(String str)
  7. hexToByte(String input)
  8. hexToBytes(String hexString)
  9. hexToByte(char char1, char char2)