Advertisement
Fundamentalen

BinaryToDecimalNumber

Mar 26th, 2014
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. using System;
  2.  
  3. class BinaryToDecimalNumber
  4. {
  5.     static void Main()
  6.     {
  7.     Console.Write("Enter your binary number: ");
  8.         string binary = Console.ReadLine();
  9.  
  10.         long dec = 0;
  11.  
  12.         for (int i = 0; i < binary.Length; i++)
  13.         {
  14.             if (binary[binary.Length - i - 1] == '0')
  15.             {
  16.                 continue;
  17.             }
  18.  
  19.             dec += (long)Math.Pow(2, i);
  20.         }
  21.  
  22.         Console.WriteLine(dec);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement