Odpowiedź :
Odpowiedź:
using System;
using System.IO;
public class Program
{
private static string Konwertuj(string liczba, int opcja)
{
switch (opcja)
{
case 1:
int dec = Convert.ToInt32(liczba, 10);
return Convert.ToString(dec, 16);
case 2:
int hex = Convert.ToInt32(liczba, 16);
return Convert.ToString(hex, 10);
case 3:
int oct = Convert.ToInt32(liczba, 8);
return Convert.ToString(oct, 2);
default:
int bin = Convert.ToInt32(liczba, 2);
return Convert.ToString(bin, 8);
}
}
public static void Main()
{
while (true) {
Console.WriteLine("1. DEC => HEX\n" +
"2. HEX => DEC\n3. OCT => BIN\n4. BIN => OCT");
Console.WriteLine("Podaj liczbe i opcje: ");
string n = Console.ReadLine();
int o = int.Parse(Console.ReadLine());
if (o < 1 || o > 4) return;
Console.WriteLine("\n" + Konwertuj(n, o) + "\n");
}
}
}