Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- namespace ConsoleApp1
- {
- class Program
- {
- static int BinToDec(string s, int k = 1)
- {
- if (s.Length > 0)
- return (s[s.Length - 1] - '0')*k + BinToDec(s.Substring(0, s.Length - 1), k * 2);
- return 0;
- }
- static void Main()
- {
- Console.Write("Enter binary number: ");
- string a = Console.ReadLine();
- Console.WriteLine("To dec : " + BinToDec(a));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement