Java Hex Convert To fromHexString(String input)

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

Description

from Hex String

License

Open Source License

Declaration

public static byte[] fromHexString(String input) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] fromHexString(String input) {
        if (input == null || input.trim().length() == 0 || input.trim().length() % 2 != 0) {
            throw new IllegalArgumentException(
                    "Input " + input + " is not valid. Must be not empty and length%2=0");
        }//  www  .  j a  v  a2 s  .  c  om

        byte[] result = new byte[input.length() / 2];
        for (int i = 0; i < input.length(); i += 2) {
            int intValue = Integer.valueOf(input.substring(i, i + 2), 16);
            result[i / 2] = (byte) (0x000000ff & intValue);
        }
        return result;
    }
}

Related

  1. fromHexString(String hexString)
  2. fromHexString(String hexString)
  3. fromHexString(String hexString)
  4. fromHexString(String in)
  5. fromHexString(String input)
  6. fromHexString(String input)
  7. fromHexString(String s)
  8. fromHexString(String s)
  9. fromHexString(String s)