Android Hex String to Byte Array Convert hexStr2Bytes(String src)

Here you can find the source of hexStr2Bytes(String src)

Description

hex Str Bytes

Declaration

public static byte[] hexStr2Bytes(String src) 

Method Source Code

//package com.java2s;

public class Main {

    public static byte[] hexStr2Bytes(String src) {
        int m = 0, n = 0;
        int l = src.length() / 2;
        System.out.println(l);/*from w ww.java2 s .c o m*/
        byte[] ret = new byte[l];
        for (int i = 0; i < l; i++) {
            m = i * 2 + 1;
            n = m + 1;
            ret[i] = uniteBytes(src.substring(i * 2, m),
                    src.substring(m, n));
        }
        return ret;
    }

    private static byte uniteBytes(String src0, String src1) {
        byte b0 = Byte.decode("0x" + src0).byteValue();
        b0 = (byte) (b0 << 4);
        byte b1 = Byte.decode("0x" + src1).byteValue();
        byte ret = (byte) (b0 | b1);
        return ret;
    }
}

Related

  1. hexStringToByteArray(String s)
  2. hexStringToBytes(String s)
  3. hex2bytes(String hex)
  4. hexStr2ByteArr(String paramString)
  5. hexStr2ByteArr(String str)
  6. hexStr2Str(String hexStr)
  7. toByte(String hexString)
  8. toBytesFromHexString(String digits)
  9. hexStringToBytes(String s)