Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp17
- {
- class Program
- {
- static void Main(string[] args)
- {
- int cislo = 0;
- Console.WriteLine("Z jaké soustavy?");
- string soustava = Console.ReadLine();
- Console.WriteLine("Zadej hodnotu");
- string hodnota = Console.ReadLine();
- hodnota = hodnota.ToUpper();
- Console.WriteLine("Do jaké soustavy?");
- string DO = Console.ReadLine();
- if (soustava =="HEX")
- {
- if (DO == "DEC")
- {
- for (int i = 0; i < hodnota.Length; i++)
- {
- if ((hodnota[i] >= '0' && hodnota[i] <= '9') || (hodnota[i] >= 'A' && hodnota[i] <= 'F'))
- {
- cislo = cislo * 16;
- if (hodnota[i] >= '0' && hodnota[i] <= '9')
- {
- cislo += (hodnota[i] - '0');
- }
- else
- {
- cislo += (hodnota[i] - 'A') + 10;
- }
- }
- }
- Console.WriteLine(cislo);
- }
- else if (DO == "BIN")
- {
- for (int i = 0; i < hodnota.Length; i++)
- {
- if ((hodnota[i] >= '0' && hodnota[i] <= '9')
- || (hodnota[i] >= 'A' && hodnota[i] <= 'F'))
- {
- cislo = cislo * 16;
- if (hodnota[i] >= '0' && hodnota[i] <= '9')
- {
- cislo += (hodnota[i] - '0');
- }
- else
- {
- cislo += (hodnota[i] - 'A') + 10;
- }
- }
- }
- string cislotext = "";
- while (cislo != 0)
- {
- int tmp = cislo % 2;
- cislo = cislo / 2;
- cislotext += tmp;
- }
- char[] charArray = cislotext.ToCharArray();
- Array.Reverse(charArray);
- cislotext = new string(charArray);
- Console.WriteLine(cislotext);
- Console.ReadLine();
- }
- }
- if (soustava == "DEC")
- {
- if (DO == "BIN")
- {
- int cislo = Convert.ToInt32(hodnota);
- string cislotext = "";
- while (cislo != 0)
- {
- int tmp = cislo % 2;
- cislo = cislo / 2;
- cislotext += tmp;
- }
- char[] charArray = cislotext.ToCharArray();
- Array.Reverse(charArray);
- cislotext = new string(charArray);
- Console.WriteLine(cislotext);
- Console.ReadLine();
- }
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement