Java Hex Convert To fromHexString(byte abyte0[], int i)

Here you can find the source of fromHexString(byte abyte0[], int i)

Description

from Hex String

License

Open Source License

Parameter

Parameter Description
abyte0 a parameter
i a parameter

Declaration

public static byte[] fromHexString(byte abyte0[], int i) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  ww w. j a v a2 s  . co m
     * 
     * 
     * @param abyte0
     * @param i
     * @return
     */
    public static byte[] fromHexString(byte abyte0[], int i) {
        int j = 0;
        if (abyte0[0] == 48 && (abyte0[1] == 120 || abyte0[1] == 88)) {
            j += 2;
            i -= 2;
        }
        int k = i / 2;
        byte abyte1[] = new byte[k];
        for (int l = 0; l < k;) {
            abyte1[l] = (byte) ((hexValueOf(abyte0[j]) << 4 | hexValueOf(abyte0[j + 1])) & 0xff);
            l++;
            j += 2;
        }

        return abyte1;
    }

    /**
     * 
     * 
     * @param i
     * @return
     */
    public static int hexValueOf(int i) {
        if (i >= 48 && i <= 57)
            return i - 48;
        if (i >= 97 && i <= 102)
            return (i - 97) + 10;
        if (i >= 65 && i <= 70)
            return (i - 65) + 10;
        else
            return 0;
    }
}

Related

  1. fromHexDigit(int c)
  2. fromHexNibble(char n)
  3. fromHexNibble(final char n)
  4. fromHexShort(char a)
  5. fromHexStr(final String data)
  6. fromHexString(final String hexaString)
  7. fromHexString(final String hexString)
  8. fromHexString(final String s)
  9. fromHexString(final String str)