hex Char To Int - Java java.lang

Java examples for java.lang:char

Description

hex Char To Int

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        char ch = 'a';
        System.out.println(hexCharToInt(ch));
    }//from  w  w w  .  j a v a2 s. co  m

    private static int hexCharToInt(char ch) {
        if (ch >= '0' && ch <= '9') {
            return ch - '0';
        } else if (ch >= 'a' && ch <= 'z') {
            return ch - 97 + 10;
        } else if (ch >= 'A' && ch <= 'Z') {
            return ch - 65 + 10;
        } else {
            throw new IllegalArgumentException("Char Not Hex");
        }
    }
}

Related Tutorials