BorisSimeonov

Binary to decimal

Dec 8th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.37 KB | None | 0 0
  1. using System;
  2.  
  3. class BinaryToDecimal
  4. {
  5.     static void Main()
  6.     {
  7.         string binaryInput = Console.ReadLine();
  8.         int result = 0;
  9.         for (int cnt = 0; cnt < binaryInput.Length; cnt++ )
  10.         {
  11.             result = result << 1;
  12.             result += (int.Parse(binaryInput[cnt].ToString()) & 1);
  13.         }
  14.         Console.WriteLine(result);
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment