Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class DecToBin
- {
- static void Main()
- {
- Console.Write("Enter decimal number: ");
- long n = long.Parse(Console.ReadLine());
- string result="";
- for (; n!=0;n/=2)
- {
- if (n % 2 == 1)
- result += "1";
- else
- result += "0";
- }
- char[] forReverse = result.ToCharArray();
- Array.Reverse(forReverse);
- result = new string(forReverse);
- Console.WriteLine("Binary: "+result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment