Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Decimal_to_Base2
- {
- class Program
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Please enter the number you want to convert from decimal to binary. (has to be a whole number!)");
- int input;
- int.TryParse(Console.ReadLine(), out input);
- int quotient = input / 2;
- int remainder = quotient % 2;
- List<int> quotientList = new List<int>();
- Console.WriteLine("Quotient: " + quotient);
- quotientList.Add(quotient);
- List<int> remainderList = new List<int>();
- Console.WriteLine("Remainder: " + remainder);
- remainderList.Add(remainder);
- while (true)
- {
- var lastQuotientValue = quotientList[quotientList.Count - 1];
- quotientList.Add(lastQuotientValue / 2);
- Console.WriteLine("Quotient: " + lastQuotientValue);
- var lastRemainderValue = remainderList[remainderList.Count - 1];
- remainderList.Add(lastQuotientValue % 2);
- Console.WriteLine("Remainder: " + lastRemainderValue);
- Console.ReadLine();
- if (lastQuotientValue == 0)
- {
- Console.ReadLine();
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement