Android Hex String Create hexDecode(String str, byte[] ba, int len)

Here you can find the source of hexDecode(String str, byte[] ba, int len)

Description

hex Decode

Declaration

public static void hexDecode(String str, byte[] ba, int len) 

Method Source Code

//package com.java2s;

public class Main {
    public static void hexDecode(String str, byte[] ba, int len) {
        char[] cp = str.toCharArray();
        byte nbl = 0;
        int i = 0;
        int icp = 0;
        int iba = 0;

        for (; i < len; i++, icp++) {
            if (cp[icp] >= '0' && cp[icp] <= '9')
                nbl = (byte) (cp[icp] - '0');
            else if (cp[icp] >= 'A' && cp[icp] <= 'F')
                nbl = (byte) (cp[icp] - 'A' + 10);
            else if (cp[icp] >= 'a' && cp[icp] <= 'f')
                nbl = (byte) (cp[icp] - 'a' + 10);

            if ((i & 0x1) == 0)
                ba[iba] = (byte) (nbl << 4);
            else/*from  www. j a v a 2s .c  o m*/
                ba[iba++] |= nbl;
        }
    }
}

Related

  1. bytesToHex(byte[] bytes)
  2. encodeHex(byte[] bytes)
  3. encodeHex(byte[] pData)
  4. hex(int value, int digits)
  5. hexCharToInt(char c)
  6. hexEncode(byte[] aInput)
  7. hexify(byte bytes[])
  8. toHex(String str)
  9. toHex(String txt)