Advertisement
BorisSimeonov

Decimal To Binary

Dec 8th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2.  
  3. class DecimalToBinary
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         long userNum = long.Parse(Console.ReadLine());
  8.         bool checkFirstBit = false;
  9.         string result = "";
  10.         for (int bit = 63; bit >= 0; bit--)
  11.         {
  12.             if (!checkFirstBit && (((userNum >> bit) & 1) != 1))
  13.             {
  14.                 continue;
  15.             }
  16.             else
  17.             {
  18.                 checkFirstBit = true;
  19.                 result += ((userNum >> bit) & 1).ToString();
  20.             }
  21.         }
  22.         Console.WriteLine(result.Length == 0 ? "0" : result);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement