Java Hex Convert To fromHexString(String hex)

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

Description

from Hex String

License

Open Source License

Declaration

public static byte[] fromHexString(String hex) 

Method Source Code

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

public class Main {
    public static byte[] fromHexString(String hex) {
        return fromHex(hex.getBytes());
    }//from   w w  w  .  j  a  va  2  s. co  m

    public static byte[] fromHex(byte[] sc) {
        byte[] res = new byte[sc.length / 2];
        for (int i = 0; i < sc.length; i++) {
            byte c1 = (byte) (sc[i] - 48 < 17 ? sc[i] - 48 : sc[i] - 55);
            i++;
            byte c2 = (byte) (sc[i] - 48 < 17 ? sc[i] - 48 : sc[i] - 55);
            res[i / 2] = (byte) (c1 * 16 + c2);
        }
        return res;
    }
}

Related

  1. fromHexString(final String hexString)
  2. fromHexString(final String s)
  3. fromHexString(final String str)
  4. fromHexString(String encoded)
  5. fromHexString(String encoded)
  6. fromHexString(String hex)
  7. fromHexString(String hexString)
  8. fromHexString(String hexString)
  9. fromHexString(String hexString)