diff --git a/algorithms/math/BinaryToDecimal.cs b/algorithms/math/BinaryToDecimal.cs new file mode 100644 index 0000000..4971606 --- /dev/null +++ b/algorithms/math/BinaryToDecimal.cs @@ -0,0 +1,30 @@ +using System; + +namespace BinaryToDecimal +{ + class Program + { + static void Main(string[] args) + { + BinaryToDecimal(); + Console.ReadKey(); + } + + private static void BinaryToDecimal() + { + Console.Write("Please Enter the Binary Number: "); + int ThebinaryNumber = int.Parse(Console.ReadLine()); + int DecimalValueNumber = 0; + int Base1Number = 1; + + while (ThebinaryNumber > 0) + { + int ReminderNumber = ThebinaryNumber % 10; + ThebinaryNumber = ThebinaryNumber / 10; + DecimalValueNumber += ReminderNumber * Base1Number; + Base1Number = Base1Number * 2; + } + Console.Write("Result of Decimal Value : " + DecimalValueNumber); + } + } +} diff --git a/algorithms/math/DecimalToBinary.cs b/algorithms/math/DecimalToBinary.cs new file mode 100644 index 0000000..4d1fa45 --- /dev/null +++ b/algorithms/math/DecimalToBinary.cs @@ -0,0 +1,34 @@ +using System; + +namespace DecimalToBinary +{ + class Program + { + static void Main(string[] args) + { + + DecimalToBinary(); + + Console.ReadKey(); + } + + private static void DecimalToBinary() + { + Console.Write("Please Enter a Decimal Number: "); + + int inputDecimalNumber = Convert.ToInt32(Console.ReadLine()); + + string resultOfBinary; + + resultOfBinary = string.Empty; + while (inputDecimalNumber > 1) + { + int remainder = inputDecimalNumber % 2; + resultOfBinary = Convert.ToString(remainder) + resultOfBinary; + inputDecimalNumber /= 2; + } + resultOfBinary = Convert.ToString(inputDecimalNumber) + resultOfBinary; + Console.WriteLine("Result In Binary Number: " + resultOfBinary); + } + } +}