Advertisement
Guest User

02_DecimaToBinary

a guest
Nov 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02_DecimaToBinary
  4. {
  5.     public class Program
  6.     {
  7.         public static void Main()
  8.         {
  9.                 string input;
  10.  
  11.                 while ((input = Console.ReadLine()) != "END")
  12.                 {
  13.                     int decimalNumber = int.Parse(input);
  14.  
  15.                     string binary = string.Empty;
  16.  
  17.                     while (decimalNumber > 0)
  18.                     {
  19.                         binary += decimalNumber % 2;
  20.                         decimalNumber = decimalNumber / 2;
  21.                     }
  22.  
  23.                     for (int i = 0; i < binary.Length; i++)
  24.                     {
  25.                         Console.Write(binary[binary.Length - i - 1]);
  26.                     }
  27.                     Console.WriteLine();
  28.                 }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement