Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BinaryToDecimalNumber
- {
- static void Main()
- {
- Console.Write("Enter the binary representation of a number: ");
- string input = Console.ReadLine();
- char[] inputToArray = input.ToCharArray();
- int degree = input.Length - 1;
- long result = 0;
- for (int i = 0; degree >= 0; i++, degree--)
- {
- result += ((long)Char.GetNumericValue(inputToArray[i]) * (long)Math.Pow(2, degree));
- }
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement