Returns true is c is a hexadecimal digit (A-F, a-f, 0-9) - CSharp System

CSharp examples for System:Int32

Description

Returns true is c is a hexadecimal digit (A-F, a-f, 0-9)

Demo Code


using System;/*from  w ww .j  a  v  a2 s.  c  o  m*/

public class Main{
        /// <summary>
        /// Returns true is c is a hexadecimal digit (A-F, a-f, 0-9)
        /// </summary>
        /// <param name="c">Character to test</param>
        /// <returns>true if hex digit, false if not</returns>
        public static bool IsHexDigit(Char c)
        {
            int numChar;
            int numA = Convert.ToInt32('A');
            int num1 = Convert.ToInt32('0');
            c = Char.ToUpper(c);
            numChar = Convert.ToInt32(c);
            if (numChar >= numA && numChar < (numA + 6))
                return true;

            if (numChar >= num1 && numChar < (num1 + 10))
                return true;

            return false;
        }
}

Related Tutorials