Advertisement
wingman007

Decimal2BinarySibelSalimova

Oct 10th, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. // Sibel Salimova <sibelsalimova@abv.bg>
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace DecimalToBinary
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             int dec;
  16.             Console.WriteLine("Enter a decimal number!");
  17.             dec=int.Parse(Console.ReadLine());
  18.             int a;
  19.             string b = "";
  20.             while (dec >= 1) {
  21.                 a = dec / 2;
  22.                 b += (dec % 2).ToString();
  23.                 dec = a;
  24.             }
  25.             string bin = "";
  26.             for (int i = b.Length - 1; i >= 0; i--) {
  27.                 bin = bin + b[i];
  28.             }
  29.             Console.WriteLine("Binary: {0}", bin);
  30.             Console.Read();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement