Char To Value - CSharp System

CSharp examples for System:Char

Description

Char To Value

Demo Code


using System;/*from w w  w .java2 s .c o  m*/

public class Main{
        private static int CharToValue(char c)
        {
            int value = (int)c;

            //65-90 == uppercase letters
            if (value < 91 && value > 64)
                return value - 65;
            //50-55 == numbers 2-7
            if (value < 56 && value > 49)
                return value - 24;
            //97-122 == lowercase letters
            if (value < 123 && value > 96)
                return value - 97;

            throw new ArgumentException("Character is not a Base32 character.", "c");
        }
}

Related Tutorials