Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Problem13.BinaryToDecimal
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Input
- string binNumber = Console.ReadLine();
- // Main Logic
- long result = 0;
- int power = 1;
- for (int i = binNumber.Length - 1; i >= 0; i--)
- {
- int number = binNumber[i] - '0';
- result += number * power;
- power *= 2;
- }
- // Output
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment