Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions algorithms/math/BinaryToDecimal.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
34 changes: 34 additions & 0 deletions algorithms/math/DecimalToBinary.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}