Java Char to Hex charToHexdigit(final byte c)

Here you can find the source of charToHexdigit(final byte c)

Description

Converts the provided character into a hexadecimal value.

License

Open Source License

Parameter

Parameter Description
c the character to be converted

Return

the hexadecimal value.

Declaration

public static int charToHexdigit(final byte c) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2000-2017 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

public class Main {
    /**/* w w  w .  j  a  va2  s .  c  o m*/
     * Converts the provided character into a hexadecimal value.
     * 
     * @param c
     *                the character to be converted
     * 
     * @return the hexadecimal value.
     * */
    public static int charToHexdigit(final byte c) {
        if (c >= '0' && c <= '9') {
            return c - '0';
        } else if (c >= 'A' && c <= 'F') {
            return c - 'A' + 10;
        } else {
            return c - 'a' + 10;
        }
    }
}

Related

  1. char2Hex(char c)
  2. charToHex(char c)
  3. charToHex(char c)
  4. charToHex(char c)