Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class ConvertBinaryToDecimalNumber
- {
- static void Main ()
- {
- Console.WriteLine("Enter your Binary number, wich consist of '0' and '1':");
- string binaryStr = Console.ReadLine();
- byte [] binarics = new byte [binaryStr.Length];
- for (int i = 0; i < binaryStr.Length; i++)
- {
- binarics [i] = byte.Parse(Convert.ToString((binaryStr [i])));
- }
- Array.Reverse(binarics);
- long numDecimal = 0;
- long multiplier = 1;
- foreach (var digit in binarics)
- {
- numDecimal += (digit * multiplier);
- multiplier *= 2;
- }
- Console.WriteLine("The Binary number in Decimal system looks like DECIMAL = {0} !",
- numDecimal);
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement