using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Systems
{
class Program
{
static char ToChar(int input)
{
switch (input % 16)
{
case 10:
return 'A';
case 11:
return 'B';
case 12:
return 'C';
case 13:
return 'D';
case 14:
return 'E';
case 15:
return 'F';
}
return 'Z';
}
static string Reverse(string input)
{
string output = "";
for (int i = input.Length - 1; i >= 0; i--)
{
output += input[i];
}
return output;
}
static string ToVosm(int input)
{
string output = "";
while (input > 7)
{
output += input % 8;
input /= 8;
}
output += input;
return Reverse(output);
}
static string ToShest(int input)
{
string output = "";
while (input > 15)
{
if ( input % 16 > 9)
{
output += ToChar(input % 16);
}
else
{
output += input % 16;
}
input /= 16;
}
if (input > 9)
{
output += ToChar(input);
}
else
{
output += input;
}
return Reverse(output);
}
static string SumVosm(string input1, string input2)
{
int buf = 0;
string output = "";
string temp = input1;
int[,] tabl = new int[8, 8] { { 0, 1, 2, 3, 4, 5, 6, 7 },
{ 1, 2, 3, 4, 5, 6, 7, 10 },
{ 2, 3, 4, 5, 6, 7, 10, 11 },
{ 3, 4, 5, 6, 7, 10, 11, 12 },
{ 4, 5, 6, 7, 10, 11, 12, 13 },
{ 5, 6, 7, 10, 11, 12, 13, 14 },
{ 6, 7, 10, 11, 12, 13, 14, 15 },
{ 7, 10, 11, 12, 13, 14, 15, 16 }, };
for (int i = 0; i < Math.Min(input1.Length, input2.Length); i++)
{
output += tabl[input1[i], input2[i]] % 10;
}
return output;
}
static void Main(string[] args)
{
Console.Write("Введите число: ");
int input = int.Parse(Console.ReadLine());
string vosm = Convert.ToString(input, 8);
string shest = Convert.ToString(input, 16);
Console.WriteLine($"Восьмеричная система: {vosm}; Шестнадцатеричная система: {shest}");
string vosm_ = ToVosm(input);
string shest_ = ToShest(input);
Console.WriteLine($"Восьмеричная система: {vosm_}; Шестнадцатеричная система: {shest_}");
Console.WriteLine($"Сложение восьмеричных чисел: {SumVosm(vosm,vosm_)}");
}
}
}