Advertisement
Teodor92

BinaryToDecimal

Jan 15th, 2013
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. /* Write a program to convert binary
  2.  * numbers to their decimal representation.
  3.  */
  4.  
  5. using System;
  6.  
  7. class BinaryToDecimal
  8. {
  9.     static void Main()
  10.     {
  11.         string input = Console.ReadLine();
  12.         int decNum = 0;
  13.         for (int i = 0; i < input.Length; i++)
  14.         {
  15.             decNum = decNum << 1;
  16.             if (input[i] == '1')
  17.             {
  18.                 decNum = decNum ^ 1;
  19.             }
  20.         }
  21.         Console.WriteLine(decNum);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement