Advertisement
Opteronic

cs num Binary to Decimal Number System

Feb 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.35 KB | None | 0 0
  1. using System;
  2.  
  3. class BinarytoDecimal
  4. {
  5.     static void Main()
  6.     {
  7.         char[] chars = Console.ReadLine().ToCharArray();
  8.         long sum = 0;
  9.  
  10.         for (int i = (chars.Length-1); i >= 0 ; i-- )
  11.             if (chars[i] == '1')
  12.                 sum += (long)Math.Pow(2, ((chars.Length-1)-i));
  13.  
  14.         Console.WriteLine(sum);
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement