Advertisement
Guest User

nightmare nightmare nightmare nightmare nightmare

a guest
Feb 19th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Decimal_to_Base2
  8. {
  9.     class Program
  10.     {
  11.         public static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Please enter the number you want to convert from decimal to binary. (has to be a whole number!)");
  14.             int input;
  15.             int.TryParse(Console.ReadLine(), out input);
  16.  
  17.             int quotient = input / 2;
  18.             int remainder = quotient % 2;
  19.  
  20.             List<int> quotientList = new List<int>();
  21.             Console.WriteLine("Quotient: " + quotient);
  22.             quotientList.Add(quotient);
  23.  
  24.             List<int> remainderList = new List<int>();
  25.             Console.WriteLine("Remainder: " + remainder);
  26.             remainderList.Add(remainder);
  27.  
  28.             while (true)
  29.             {
  30.                 var lastQuotientValue = quotientList[quotientList.Count - 1];
  31.                 quotientList.Add(lastQuotientValue / 2);
  32.                 Console.WriteLine("Quotient: " + lastQuotientValue);
  33.  
  34.                 var lastRemainderValue = remainderList[remainderList.Count - 1];
  35.                 remainderList.Add(lastQuotientValue % 2);
  36.                 Console.WriteLine("Remainder: " + lastRemainderValue);
  37.  
  38.                 Console.ReadLine();
  39.  
  40.                 if (lastQuotientValue == 0)
  41.                 {
  42.                     Console.ReadLine();
  43.                     break;
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement