Advertisement
dimipan80

6.16Loop_DecimalUnSignNumberToBinarySystem

Mar 25th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class ConvertDecimalNumberToBinarySystem
  5. {
  6.     static void Main ()
  7.     {
  8.         Console.Write("Enter a whole non-negative Decimal Number, DECIMAL = ");
  9.         string numberStr = Console.ReadLine();
  10.         ulong numDecimal = ulong.Parse(numberStr);
  11.  
  12.         List<byte> binarics = new List<byte>();
  13.         ulong quotient = 0;
  14.         byte remainder = 0;
  15.         checked
  16.         {
  17.             do
  18.             {
  19.                 quotient = numDecimal / 2;
  20.                 remainder = (byte)(numDecimal % 2);
  21.                 binarics.Add(remainder);
  22.                 numDecimal = quotient;
  23.             } while (quotient != 0);
  24.         }
  25.             Console.WriteLine("That Decimal number in Binary system is:");
  26.             Console.Write("BINARY NUMBER = ");
  27.             binarics.Reverse();
  28.             foreach (var digit in binarics)
  29.             {
  30.                 Console.Write("{0}", digit);
  31.             }
  32.             Console.WriteLine();
  33.             Console.ReadLine();        
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement