Advertisement
Fundamentalen

DecimalToBinary

Mar 26th, 2014
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. using System;
  2.  
  3. class DecimalToBinary
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("Enter your decimal number: ");
  8.         long dec = long.Parse(Console.ReadLine());
  9.  
  10.         long rest;
  11.         string binary = string.Empty;
  12.  
  13.         while (dec > 0)
  14.         {
  15.             rest = dec % 2;
  16.             dec /= 2;
  17.             binary = rest.ToString() + binary;
  18.         }
  19.  
  20.         Console.WriteLine(binary);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement