Android Hex String to Byte Array Convert hex2byte(String inputString)

Here you can find the source of hex2byte(String inputString)

Description

hexbyte

Declaration

private static byte[] hex2byte(String inputString) 

Method Source Code

//package com.java2s;

public class Main {

    private static byte[] hex2byte(String inputString) {
        if (inputString == null || inputString.length() < 2) {
            return new byte[0];
        }/*w  w w . j  a  v a  2s.c o  m*/
        inputString = inputString.toLowerCase();
        int l = inputString.length() / 2;
        byte[] result = new byte[l];
        for (int i = 0; i < l; ++i) {
            String tmp = inputString.substring(2 * i, 2 * i + 2);
            result[i] = (byte) (Integer.parseInt(tmp, 16) & 0xFF);
        }
        return result;
    }
}

Related

  1. hexStringToBytes(String hex)
  2. hexStringToBytes(String hexString)
  3. hexStringToBytes(String hexString)
  4. toByte(String hexString)
  5. toByte(String hexString)
  6. fromHex(String hex)
  7. fromHex(String hex)
  8. hexToBytes(String str)
  9. hexToByte(String input)