Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class ConvertDecimalNumberToBinarySystem
- {
- static void Main ()
- {
- Console.Write("Enter a whole non-negative Decimal Number, DECIMAL = ");
- string numberStr = Console.ReadLine();
- ulong numDecimal = ulong.Parse(numberStr);
- List<byte> binarics = new List<byte>();
- ulong quotient = 0;
- byte remainder = 0;
- checked
- {
- do
- {
- quotient = numDecimal / 2;
- remainder = (byte)(numDecimal % 2);
- binarics.Add(remainder);
- numDecimal = quotient;
- } while (quotient != 0);
- }
- Console.WriteLine("That Decimal number in Binary system is:");
- Console.Write("BINARY NUMBER = ");
- binarics.Reverse();
- foreach (var digit in binarics)
- {
- Console.Write("{0}", digit);
- }
- Console.WriteLine();
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement