ScreeM

13.Binary to Decimal Number

Apr 7th, 2014
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. using System;
  2. class BinaryToDecimalNumber
  3. {
  4. static void Main()
  5. {
  6. Console.Write("Enter your binary number: ");
  7. string binary = Console.ReadLine();
  8. // Console.WriteLine(Convert.ToInt64(binary, 2));
  9. long dec = 0;
  10.  
  11. for (int i = 0; i < binary.Length; i++)
  12. {
  13. if (binary[binary.Length - i - 1] == '0')
  14. {
  15. continue;
  16. }
  17.  
  18. dec += (long)Math.Pow(2, i);
  19. }
  20.  
  21. Console.WriteLine(dec);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment