Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using System;
  2. class BinaryToDecimalNumber
  3. {
  4.     static void Main()
  5.     {
  6.         Console.Write("Enter the binary representation of a number: ");
  7.         string input = Console.ReadLine();
  8.         char[] inputToArray = input.ToCharArray();
  9.         int degree = input.Length - 1;
  10.         long result = 0;
  11.  
  12.         for (int i = 0; degree >= 0; i++, degree--)
  13.         {
  14.             result += ((long)Char.GetNumericValue(inputToArray[i]) * (long)Math.Pow(2, degree));
  15.         }
  16.         Console.WriteLine(result);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement