Advertisement
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 _13.BinaryToDecimal
- {
- class BinaryToDecimal
- {
- static void Main()
- {
- Console.Write("Enter a binary numbes as string: ");
- string binary = Console.ReadLine();
- int digit = 0;
- int power = 0;
- long sum = 0L;
- for (int i = binary.Length - 1; i >= 0; i--)
- {
- digit = binary[i] - '0';
- double temp = Math.Pow(2, power);
- sum += (int)temp * digit;
- power++;
- }
- Console.WriteLine(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement