Java Number Value Of valueOf(char hexChar)

Here you can find the source of valueOf(char hexChar)

Description

Returns the hex value of the given character

License

Open Source License

Parameter

Parameter Description
hexChar Hex character, such as '0' or 'A'

Return

The value of the hex character.

Declaration

public static byte valueOf(char hexChar) 

Method Source Code

//package com.java2s;
/*//  w  ww .j  a  v  a  2  s .  c  om
 * File:                HashFunctionUtil.java
 * Authors:             Kevin R. Dixon
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 *
 * Copyright Jan 26, 2011, Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the U.S. Government.
 * Export of this program may require a license from the United States
 * Government. See CopyrightHistory.txt for complete details.
 *
 */

public class Main {
    /**
     * Char table for convenience
     */
    static final char[] HEX_CHAR_TABLE = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
            'e', 'f' };

    /**
     * Returns the hex value of the given character
     * @param hexChar
     * Hex character, such as '0' or 'A'
     * @return
     * The value of the hex character.
     */
    public static byte valueOf(char hexChar) {
        hexChar = Character.toLowerCase(hexChar);
        for (byte i = 0; i < HEX_CHAR_TABLE.length; i++) {
            if (hexChar == HEX_CHAR_TABLE[i]) {
                return i;
            }
        }
        throw new IllegalArgumentException(hexChar + " is not a hex char");
    }
}

Related

  1. valueOf(boolean flag)
  2. valueOf(boolean tmp)
  3. valueOf(Boolean value)
  4. valueOf(Boolean value)
  5. valueOf(char c)
  6. valueOf(Class enumType, int ordinal)
  7. valueOf(final Boolean value)
  8. valueOf(float f)
  9. valueOf(int i)