Java Hex Convert To fromHex(String hexString)

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

Description

from Hex

License

Open Source License

Declaration

public static byte[] fromHex(String hexString) 

Method Source Code

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

public class Main {
    public static byte[] fromHex(String hexString) {
        if (hexString == null) {
            return null;
        }// w  w w .j a va2s.  c  o  m

        int len = hexString.length();
        if (len % 2 != 0) {
            throw new IllegalArgumentException();
        }

        byte[] data = new byte[len / 2];
        for (int i = 0; i < data.length; i++) {
            // String hexByte = hexString.substring(i * 2, i * 2 + 2);
            //
            // Integer num = Integer.decode("0x" + hexByte);
            // data[i] = num.byteValue();
            data[i] = (byte) (Integer.parseInt(hexString.substring(i * 2, i * 2 + 2), 16) & 0xff);
        }

        return data;
    }
}

Related

  1. fromHex(String hex)
  2. fromHex(String hex)
  3. fromHex(String hexBytes)
  4. fromHex(String hexData)
  5. fromHex(String hexStr)
  6. fromHex(String hexString)
  7. fromHex(String input, int max)
  8. fromHex(String s)
  9. fromHex(String s)