Android Hex String to Byte Array Convert hexToBytes(String str)

Here you can find the source of hexToBytes(String str)

Description

hex To Bytes

Declaration

public static byte[] hexToBytes(String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte[] hexToBytes(String str) {
        if (str == null) {
            return null;
        } else if (str.length() < 2) {
            return null;
        } else {/*from ww  w  .j a  v  a 2 s . com*/
            int len = str.length() / 2;
            byte[] buffer = new byte[len];
            for (int i = 0; i < len; i++) {
                buffer[i] = (byte) Integer.parseInt(
                        str.substring(i * 2, i * 2 + 2), 16);
            }
            return buffer;
        }
    }
}

Related

  1. toByte(String hexString)
  2. toByte(String hexString)
  3. hex2byte(String inputString)
  4. fromHex(String hex)
  5. fromHex(String hex)
  6. hexToByte(String input)
  7. hexToBytes(String hexString)
  8. hexToByte(char char1, char char2)
  9. hexStringToByteArray(String s)