Java Hex to Byte convertHexDigit(byte c)

Here you can find the source of convertHexDigit(byte c)

Description

convert Hex Digit

License

Open Source License

Parameter

Parameter Description
c An ASCII encoded character 0-9 a-f A-F

Return

The byte value of the character 0-16.

Declaration

public static byte convertHexDigit(byte c) 

Method Source Code

//package com.java2s;
//  are made available under the terms of the Eclipse Public License v1.0

public class Main {
    /**/* ww  w .  ja  v a  2  s.  co m*/
     * @param c An ASCII encoded character 0-9 a-f A-F
     * @return The byte value of the character 0-16.
     */
    public static byte convertHexDigit(byte c) {
        byte b = (byte) ((c & 0x1f) + ((c >> 6) * 0x19) - 0x10);
        if (b < 0 || b > 15)
            throw new NumberFormatException("!hex " + c);
        return b;
    }

    /**
     * @param c An ASCII encoded character 0-9 a-f A-F
     * @return The byte value of the character 0-16.
     */
    public static int convertHexDigit(int c) {
        int d = ((c & 0x1f) + ((c >> 6) * 0x19) - 0x10);
        if (d < 0 || d > 15)
            throw new NumberFormatException("!hex " + c);
        return d;
    }
}

Related

  1. convertHexCharacterToHalfByte(char character)
  2. convertHexDigit(byte b)
  3. convertHexDigit(byte b)
  4. convertHexDigit(byte b)
  5. convertHexDigit(byte b)