blikk info infothek forum galerie sitemap

Umwandlung von Dezimalzahlen in Hexadezimalzahlen

zur Aufgabenstellung

 

using System;

using System.Collections.Generic;

using System.Text;

 

namespace Hexa

{

    class Program

    {

        static void Main(string[] args)

        {

           int  modulo;

            int zahl;

            int rest;

            string hexa = ("");

            string ausgabe = "";

            Console.WriteLine("t Umrechner von Zahlen im Dezimalsystem in des Hexadezimalsystemn");

            Console.Write("Geben sie bitte eine beliebige Zahl ein (im Dezimalsystem): ");

            zahl = Convert.ToInt32(Console.ReadLine());

            rest = zahl;

            while (rest >0)

            { modulo =( rest % 16);

                rest = (rest  / 16);

 

                switch (modulo)

                {

                    case 0: hexa = "0";

                        break;

                    case 1: hexa = "1";

                        break;

                    case 2: hexa ="2";

                        break;

                    case 3: hexa ="3";

                        break;

                    case 4: hexa ="4";

 

                        break;

                    case 5: hexa = "5";

 

                        break;

                    case 6: hexa = "6";

                        break;

                    case 7: hexa = "7";

                        break;

                    case 8: hexa ="8";

                        break;

                    case 9: hexa ="9";

                        break;

                    case 10: hexa ="A";

                        break;

                    case 11: hexa ="B";

                        break;

                    case 12: hexa ="C";

                        break;

                    case 13: hexa = hexa + "D";

                        break;

                    case 14: hexa = hexa + "E";

                        break;

                    case 15: hexa = hexa + "F";

                    break;

            }

           

                ausgabe = hexa + ausgabe;

               

              

            }

            if (ausgabe == "")

                    ausgabe = "0";

            Console.Write(ausgabe+" im Hexadezimalsystem");

           

            Console.Read();

        }

    }

}



nach oben