Advertisement
remote87

Numeral System Conversions

Aug 13th, 2015
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace NumeralSystemConversions
  4. {
  5.     class NumeralSystemConversions
  6.     {
  7.         static void Main()
  8.         {
  9.             Console.WriteLine("Enter a decimal number to convert it in binary and hexadecimal system:");
  10.             int decNumber = int.Parse(Console.ReadLine());
  11.             string hexValue = decNumber.ToString("X");
  12.             Console.WriteLine("Your number in hecadecimal system is: {0}", hexValue);
  13.             string binValue = Convert.ToString(decNumber, 2);
  14.             Console.WriteLine("Your number in binary system is: {0}", binValue);
  15.             for (int i = 0; i < Console.WindowWidth; i++)
  16.             {
  17.                 Console.Write("*");
  18.             }
  19.             Console.WriteLine("Enter a binary number to convert it in decimal and hexadecimal system:");
  20.             string binNumber = Console.ReadLine();
  21.             int decValue = Convert.ToInt32(binNumber, 2);
  22.             Console.WriteLine("Your number in decimal system is: {0}", decValue);
  23.             string decToHex = decValue.ToString("X");
  24.             Console.WriteLine("Your number in hexadecimal system is: {0}", decToHex);
  25.             for (int i = 0; i < Console.WindowWidth; i++)
  26.             {
  27.                 Console.Write("*");
  28.             }
  29.             Console.WriteLine("Enter a hexadecimal number to convert it in decimal and binary system:");
  30.             string hexNumber = Console.ReadLine();
  31.             int hexToDec = Convert.ToInt32(hexNumber, 16);
  32.             Console.WriteLine("Your number is decimal system is: {0}", hexToDec);
  33.             string hexToBin = Convert.ToString(hexToDec, 2);
  34.             Console.WriteLine("Your number in binary system is: {0}", hexToBin);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement