Java Byte Array Create toBytes(String hexStr)

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

Description

to Bytes

License

Open Source License

Declaration

public static byte[] toBytes(String hexStr) 

Method Source Code

//package com.java2s;
/*/* w w w.  ja  va  2s.  c o  m*/
 * Author   : Ardika Rommy Sanjaya
 * Website   : http://ardikars.com
 * Contact   : contact@ardikars.com
 * License   : Lesser GNU Public License Version 3
 */

public class Main {
    public static byte[] toBytes(String hexStr) {
        String src = hexStr.replaceAll("\\s+", "").trim();
        int len = src.length();
        byte[] data = new byte[len / 2];
        for (int i = 0; i < len; i += 2) {
            data[i / 2] = (byte) ((Character.digit(src.charAt(i), 16) << 4)
                    + Character.digit(src.charAt(i + 1), 16));
        }
        return data;
    }
}

Related

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