Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BinaryToDecimalNumber
- {
- static void Main()
- {
- string binary = Console.ReadLine();
- char[] arr = binary.ToCharArray();
- long sum = 0;
- long bit = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- bit = Convert.ToInt64(arr[i]) - 48;
- sum += bit * (long)(Math.Pow(2, (arr.Length - (i + 1))));
- }
- Console.WriteLine(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement