Java Byte Array Create toByteArray(String hexStr)

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

Description

to Byte Array

License

Apache License

Declaration

private static byte[] toByteArray(String hexStr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    private static byte[] toByteArray(String hexStr) {
        if (hexStr.length() < 1)
            return null;
        byte[] result = new byte[hexStr.length() / 2];
        for (int i = 0; i < hexStr.length() / 2; i++) {
            int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
            int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
            result[i] = (byte) (high * 16 + low);
        }/*from   w  w w.  ja  v a2 s .c  o  m*/
        return result;
    }
}

Related

  1. toByteArray(String content, String charsetName)
  2. toByteArray(String hex)
  3. toByteArray(String hex)
  4. toByteArray(String hex)
  5. toByteArray(String hex)
  6. toByteArray(String hexString)
  7. toByteArray(String hexString)
  8. toByteArray(String hexString)
  9. toByteArray(String map)