Java Byte Array Create toBytes(String hex)

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

Description

to Bytes

License

Open Source License

Parameter

Parameter Description
hex a parameter

Declaration

public static byte[] toBytes(String hex) 

Method Source Code

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

public class Main {
    /**//from   w w  w .jav a 2 s .  c  o m
     * @param hex
     * @return
     */
    public static byte[] toBytes(String hex) {
        byte[] bts = new byte[hex.length() / 2];
        for (int i = 0; i < bts.length; i++) {
            bts[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
        }
        return bts;
    }
}

Related

  1. toBytes(short s)
  2. toBytes(short sVal, byte[] bytes, boolean bigEndian)
  3. toBytes(short value)
  4. toBytes(short value)
  5. toBytes(String hex)
  6. toBytes(String hex)
  7. toBytes(String hex)
  8. toBytes(String hex)
  9. toBytes(String hex)