Advertisement
Infiniti_Inter

3

Nov 24th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using System.Text;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.  
  10.  
  11.     class Program
  12.     {
  13.  
  14.         static int BinToDec(string s, int k = 1)
  15.         {
  16.             if (s.Length > 0)
  17.                 return (s[s.Length - 1] - '0')*k + BinToDec(s.Substring(0, s.Length - 1), k * 2);
  18.             return 0;
  19.         }
  20.  
  21.         static void Main()
  22.         {
  23.             Console.Write("Enter binary number: ");
  24.             string a = Console.ReadLine();
  25.             Console.WriteLine("To dec : " + BinToDec(a));
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement