Advertisement
Masovski

[C# Basics][Loops-HW] 14. Decimal to Binary Number

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