Advertisement
vencinachev

BIN->DEC

Jan 30th, 2022
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Loops
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.Write("Enter BIN: ");
  10.             int num = int.Parse(Console.ReadLine());
  11.             int num1 = num;
  12.             int dec = 0;
  13.             int power = 0;
  14.             while (num != 0)
  15.             {
  16.                 int digit = num % 10;
  17.                 dec += digit * (int)Math.Pow(2, power);
  18.                 power++;
  19.                 num /= 10;
  20.             }
  21.             Console.WriteLine($"{num1}(2) = {dec}(10)");
  22.         }
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement