Java Char to Int charToInt(char c)

Here you can find the source of charToInt(char c)

Description

Converts character to number.

License

Academic Free License

Parameter

Parameter Description
c a parameter

Declaration

public static int charToInt(char c) 

Method Source Code

//package com.java2s;
//License from project: Academic Free License 

public class Main {
    public static final int PAD_VALUE = 65;

    /**//  w  w  w  .  j  a v  a2s .  c o m
     * Converts character to number.  Array lookup would be faster.
     * 
     * @param c
     * @return
     */
    public static int charToInt(char c) {
        int val = PAD_VALUE;

        // first the capital letters
        if (c >= 'A' && c <= 'Z') {
            val = c - 'A';
        }
        // lower case
        else if (c >= 'a' && c <= 'z') {
            val = c - 'a' + 26;
        }
        // numbers
        else if (c >= '0' && c <= '9') {
            val = c - '0' + 52;
        }
        // specials
        else if (c == '+') {
            val = 62;
        } else if (c == '/') {
            val = 63;
        }

        return val;
    }
}

Related

  1. charToIndex(char c)
  2. charToIndex(Character c)
  3. charToInt(char c)
  4. charToInt(char c)
  5. charToInt(char c)
  6. charToInt(char c)
  7. twoChars2Int(char ch, char cl)