ValentinV

BinaryToDecimal

Mar 3rd, 2016
110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem13.BinaryToDecimal
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12.  
  13. {
  14. // Input
  15. string binNumber = Console.ReadLine();
  16.  
  17. // Main Logic
  18. long result = 0;
  19. int power = 1;
  20. for (int i = binNumber.Length - 1; i >= 0; i--)
  21. {
  22. int number = binNumber[i] - '0';
  23. result += number * power;
  24. power *= 2;
  25. }
  26.  
  27. // Output
  28. Console.WriteLine(result);
  29. }
  30. }
  31. }
RAW Paste Data