Java Hex Convert To fromHex(String bytesString)

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

Description

from Hex

License

Open Source License

Declaration

public static byte[] fromHex(String bytesString) 

Method Source Code

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

public class Main {
    public static byte[] fromHex(String bytesString) {
        int len = bytesString.length() / 2;
        if (bytesString.length() % 2 != 0) {
            throw new IllegalArgumentException("Bytes Hex string length has to be even number");
        }//  w  w  w. ja v a  2 s . c  o m
        byte[] out = new byte[len];
        for (int i = 0; i < len; i++) {
            int pos = i * 2;
            byte b = (byte) Integer.valueOf(bytesString.substring(pos, pos + 2), 16).intValue();
            out[i] = b;
        }
        return out;
    }
}

Related

  1. fromHex(final String hex)
  2. fromHex(final String hex)
  3. fromHex(final String hexValue)
  4. fromHex(final String s)
  5. fromHex(final String string, final int offset, final int count)
  6. fromHex(String encoded)
  7. fromHex(String hex)
  8. fromHex(String hex)
  9. fromHex(String hex)