• Register
  • Log in
  • Home
  • Contact

C# Hex to Decimal, Decimal to Hex and Binary Conversion



1) Convert Hex to Decimal
private
string HextoDecimal(string number)
    {
   try
        {
       return Convert.ToInt32(number, 16).ToString();
        }
        catch (Exception ex)
        {
       Console.Write(ex.Message);
        }
        return "";
     }

2) Convert Decimal to Hex
    private string DecimaltoHex(string number)
    {
   try
        {
       return int.Parse(number, System.Globalization.NumberStyles.HexNumber).ToString();
        }
        catch (Exception ex)
        {
       Console.Write(ex.Message);
        }
        return "";
   }

3) Convert Decimal to Binary 
    int length = 8;
        public string DeicmalToBin(int value, int leng)
        {
            try
            {
                return (leng > 1 ? DeicmalToBin(value >> 1, leng - 1) : null) + "01"[value & 1];
            }
            catch(Exception ex){
                Console.Write(ex.Message);
            }
            return "";
        }

 


© 2021 - KodeCenter beta