Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program to convert binary
- * numbers to their decimal representation.
- */
- using System;
- class BinaryToDecimal
- {
- static void Main()
- {
- string input = Console.ReadLine();
- int decNum = 0;
- for (int i = 0; i < input.Length; i++)
- {
- decNum = decNum << 1;
- if (input[i] == '1')
- {
- decNum = decNum ^ 1;
- }
- }
- Console.WriteLine(decNum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement