Java Byte Array Create toByteArray(String hex)

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

Description

Convert hex string to byte array

License

Open Source License

Parameter

Parameter Description
hexStr a parameter

Declaration

public static byte[] toByteArray(String hex) 

Method Source Code

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

public class Main {
    /***/*from   w ww. j  a  v a2  s  .  c o  m*/
     * Convert hex string to byte array
     * @param hexStr
     * @return
     */
    public static byte[] toByteArray(String hex) {
        byte[] byteArray = new byte[hex.length() / 2];
        for (int i = 0; i < byteArray.length; i++) {
            byteArray[i] = (byte) Integer.parseInt(hex.substring((i * 2), ((i * 2) + 2)), 16);
        }
        return byteArray;
    }
}

Related

  1. toByteArray(String bytesStr, int byteLength)
  2. toByteArray(String content, String charsetName)
  3. toByteArray(String hex)
  4. toByteArray(String hex)
  5. toByteArray(String hex)
  6. toByteArray(String hexStr)
  7. toByteArray(String hexString)
  8. toByteArray(String hexString)
  9. toByteArray(String hexString)