Java Hex Convert To fromHex(String hexBytes)

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

Description

from Hex

License

Open Source License

Declaration

public static byte[] fromHex(String hexBytes) 

Method Source Code

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

public class Main {
    public static byte[] fromHex(String hexBytes) {
        byte[] result = new byte[(hexBytes.length() + 1) / 2];
        int n = 0;
        for (char c : hexBytes.toCharArray()) {
            int digit = Character.digit(c, 16);
            if (digit == -1)
                throw new IllegalArgumentException("Not a valid hex digit: " + c);
            int index = n >>> 1;
            if ((n & 1) == 0) {
                result[index] = (byte) digit;
            } else {
                result[index] = (byte) ((result[index] << 4) | digit);
            }//ww w.j  a v a2s.c o  m

            n++;
        }

        return result;
    }
}

Related

  1. fromHex(String hex)
  2. fromHex(String hex)
  3. fromHex(String hex)
  4. fromHex(String hex)
  5. fromHex(String hex)
  6. fromHex(String hexData)
  7. fromHex(String hexStr)
  8. fromHex(String hexString)
  9. fromHex(String hexString)