Autor Beitrag
Rakeem
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Di 27.04.10 21:54 
So das programm kann halt von dezimal zahlen nach binär umrechnen.

Aber die ausgabe ist wenn ich 12 eingebe 0011 soll ja aber 1100 ausgegeben werden.

bitte um vorschläge

programm ist in c#
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 27.04.10 22:04 
In Zeile 5 ist der Fehler!

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Namenlosnameless
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: Di 27.04.10 22:05 
Ja genau da fehlt eine Using-DIrektive nämlcih:
ausblenden C#-Quelltext
1:
using System.Ich.werde.niemehr.ohne.Quellcode.posten;					


ich würd sagen, dass so ohne Quell-Code nichts geht!

Ich mein hier im Forum kann niemand hellsehen! Woher sollen wir wissen wo dein Fehler liegt?

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>
Rakeem Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Di 27.04.10 22:07 
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
using System;

namespace Umrechner
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intRest;
            int intErgebnis, intZahl, a = 0;

            Console.Write("\t\t\t***************************************\n");
            Console.Write("\t\t\t*  Umrechnung von Dezimal nach Binär  *\n");
            Console.Write("\t\t\t***************************************\n\n");

            Console.Write("\t\t\tGeben Sie bitte eine Zahl ein:\t\t");
            intZahl = Convert.ToInt32(Console.ReadLine());
            Console.Write("\n\n");
            intRest = new int[intZahl + 1];
            if (intZahl >= 1)
            {
                do
                {
                    if (intZahl % 2 == 0)
                    {
                        intRest[a] = 0;
                    }
                    else
                    {
                        intRest[a] = 1;
                    }
                    intErgebnis = intZahl / 2;
                    Console.Write("{0}", intRest[a]);
                    intZahl = intErgebnis;
                }
                while (intErgebnis > 0);
                Console.Write("\n\n");
            }
        }
    }
}



sry

Moderiert von user profile iconKha: C#-Tags hinzugefügt
Namenlosnameless
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: Di 27.04.10 22:27 
schon mal bedacht dass du bei der binären divison die zahl rückwärts rausbekommst?

also wenn du bei 12: 0011 herausbekommst dann musst du die zahl umdrehen!

also aus 0011 wird 1100

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>
Rakeem Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Di 27.04.10 22:32 
ja bedacht hab ich das schon aber ich weiss nicht wie ich das hinkrieg
Namenlosnameless
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: Di 27.04.10 22:41 
keine Ahnung ob das jetzt das schnellste oder einfachste ist!

du schreibst mit einer schleife alle zahlen in einen Array bzw List<string> und ließt diesen dann verkehrt herum aus!

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>
Flitzs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 123
Erhaltene Danke: 7

Win7 x64/86 WinServer 2008 R2 x64
C#/C++/C VS2010
BeitragVerfasst: Di 27.04.10 22:49 
Einfacher geht es mit den .Net-Klassen:

Convert.ToString(Input, 2) liefert dir den entsprechenden String.

mfg Flitzs
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 27.04.10 23:25 
Es reicht doch ein einfacher String, in den die Zeichen in der richtigen Reihenfolge hineingeschrieben werden. Der kann dann als Ganzes auf die Konsole ausgegeben werden, fertig.
Rakeem Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Mi 28.04.10 16:16 
ok danke für eure antworten habe das mit der schleife und den array gemaxht