Advertisement
YankoZlatanov

Untitled

Feb 10th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. using System;
  2.  
  3. class BinaryToDecimalNumber
  4. {
  5.     static void Main()
  6.     {
  7.         string binary = Console.ReadLine();
  8.         char[] arr = binary.ToCharArray();
  9.         long sum = 0;
  10.         long bit = 0;
  11.         for (int i = 0; i < arr.Length; i++)
  12.         {
  13.      
  14.  
  15.             bit = Convert.ToInt64(arr[i]) - 48;
  16.             sum += bit * (long)(Math.Pow(2, (arr.Length - (i + 1))));
  17.         }
  18.         Console.WriteLine(sum);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement