<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[C++ Umwandlung Dualsystem in Dezimalsystem]]></title><description><![CDATA[<p>Hallo zusammen,<br />
habe angefangen Programmiersprachen zu lernen, leider bin ich noch nicht so weit und stehe vor einem Problem.</p>
<p>Ich möchte mit Hilfe von C++ eine 8 Bit Dualzahl in eine Dezimalzahl umwandeln lassen. Habe folgenden Quellcode geschrieben doch irgendwas passt nicht und ich komme nicht darauf.</p>
<p>Wäre super wenn mir jemand weiterhelfen könnte.</p>
<p>Quellcode:</p>
<p>/* Dualzahl in Dezimalzahl*/</p>
<p>#include &lt;iostream&gt;<br />
#include &lt;math.h&gt;</p>
<p>using namespace std;</p>
<p>int main()<br />
{<br />
int ergebnis = 0;<br />
int zahl[8];<br />
int n=0;</p>
<p>for (int stelle = 0; stelle &lt;=7; stelle ++)<br />
zahl[stelle] = 0;</p>
<p>for (int stelle = 0; stelle &lt;=7; stelle ++)<br />
{<br />
cout &lt;&lt; &quot;Bitte geben Sie das &quot; &lt;&lt; stelle + 1 &lt;&lt; &quot; von 8 Bits (von links beginnend) der Dualzahl ein: &quot;;<br />
cin &gt;&gt; zahl[stelle];<br />
}</p>
<p>for (int stelle = 7; stelle &gt;=0; stelle --)<br />
for (int n = 0; n &lt;= 7; n ++)<br />
ergebnis = ergebnis + zahl[stelle] * pow(2,n);</p>
<p>cout &lt;&lt; &quot;Die Dezimalzahl lautet: &quot; &lt;&lt; ergebnis;</p>
<p>return 0;<br />
}</p>
<p>Bin gespannt auf Eure Hilfe, danke.</p>
<p>Gruß Scriptlaie</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/299224/c-umwandlung-dualsystem-in-dezimalsystem</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 10:52:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/299224.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Feb 2012 09:20:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 09:20:38 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
habe angefangen Programmiersprachen zu lernen, leider bin ich noch nicht so weit und stehe vor einem Problem.</p>
<p>Ich möchte mit Hilfe von C++ eine 8 Bit Dualzahl in eine Dezimalzahl umwandeln lassen. Habe folgenden Quellcode geschrieben doch irgendwas passt nicht und ich komme nicht darauf.</p>
<p>Wäre super wenn mir jemand weiterhelfen könnte.</p>
<p>Quellcode:</p>
<p>/* Dualzahl in Dezimalzahl*/</p>
<p>#include &lt;iostream&gt;<br />
#include &lt;math.h&gt;</p>
<p>using namespace std;</p>
<p>int main()<br />
{<br />
int ergebnis = 0;<br />
int zahl[8];<br />
int n=0;</p>
<p>for (int stelle = 0; stelle &lt;=7; stelle ++)<br />
zahl[stelle] = 0;</p>
<p>for (int stelle = 0; stelle &lt;=7; stelle ++)<br />
{<br />
cout &lt;&lt; &quot;Bitte geben Sie das &quot; &lt;&lt; stelle + 1 &lt;&lt; &quot; von 8 Bits (von links beginnend) der Dualzahl ein: &quot;;<br />
cin &gt;&gt; zahl[stelle];<br />
}</p>
<p>for (int stelle = 7; stelle &gt;=0; stelle --)<br />
for (int n = 0; n &lt;= 7; n ++)<br />
ergebnis = ergebnis + zahl[stelle] * pow(2,n);</p>
<p>cout &lt;&lt; &quot;Die Dezimalzahl lautet: &quot; &lt;&lt; ergebnis;</p>
<p>return 0;<br />
}</p>
<p>Bin gespannt auf Eure Hilfe, danke.</p>
<p>Gruß Scriptlaie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2177484</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177484</guid><dc:creator><![CDATA[Scriptlaie]]></dc:creator><pubDate>Mon, 06 Feb 2012 09:20:38 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 09:31:44 GMT]]></title><description><![CDATA[<p>Was genau passt denn nicht? Stimmt die Ausgabe nicht? Beschwert sich dein Compiler?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2177487</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177487</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Mon, 06 Feb 2012 09:31:44 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 09:35:51 GMT]]></title><description><![CDATA[<p>sorry hab ich vergessen dazu zu schreiben.</p>
<p>Die Ausgabe ergibt entweder 0 oder 255 egal welche Dualzahl ich eingebe.</p>
<p>Das noch Abfragen fehlen die sicher stellen ob auch nur 1 oder 0 eingegeben wurde fehlt noch, weil ich erst mal das Grundgerüst haben möchte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2177490</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177490</guid><dc:creator><![CDATA[Scriptlaie]]></dc:creator><pubDate>Mon, 06 Feb 2012 09:35:51 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 09:38:58 GMT]]></title><description><![CDATA[<p>Hier der Quelltext formatiert:</p>
<pre><code class="language-cpp">/* Dualzahl in Dezimalzahl*/

#include &lt;iostream&gt;
#include &lt;math.h&gt;  // warum nicht cmath?

using namespace std;

int main()
{
    int ergebnis = 0;
    int zahl[8];
    int n=0;

    for (int stelle = 0; stelle &lt;=7; stelle ++)
        zahl[stelle] = 0;

    for (int stelle = 0; stelle &lt;=7; stelle ++)
    {
        cout &lt;&lt; &quot;Bitte geben Sie das &quot; &lt;&lt; stelle + 1 &lt;&lt; &quot; von 8 Bits (von links beginnend) der Dualzahl ein: &quot;;
        cin &gt;&gt; zahl[stelle];
    }

    for (int stelle = 7; stelle &gt;=0; stelle --)
        for (int n = 0; n &lt;= 7; n ++)  // hier noch mal int n?
            ergebnis = ergebnis + zahl[stelle] * pow(2,n);

    cout &lt;&lt; &quot;Die Dezimalzahl lautet: &quot; &lt;&lt; ergebnis;

    return 0;
}
</code></pre>
<p>Die Kommentare sind eher im Bereich der Warnungen anzusiedeln.<br />
Nix getestet.<br />
Aber mehrfach</p>
<pre><code class="language-cpp">int stelle ...
</code></pre>
<p>fördert nicht gerade die Übersichtlichkeit <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>MfG f.-th.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2177492</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177492</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Mon, 06 Feb 2012 09:38:58 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 09:47:52 GMT]]></title><description><![CDATA[<p>Das ist ja super von Euch.</p>
<p>Habe das nun auf cmath geändert, spielt jedoch keine Rolle oder? Hatte irgendwie math.h im Kopf.</p>
<p>Wie kann ich es verhindern das ich</p>
<pre><code class="language-cpp">int stelle...
</code></pre>
<p>so oft schreibe???</p>
<p>Mit dem Kommentar</p>
<pre><code class="language-cpp">for (int n = 0; n &lt;= 7; n ++)  // hier noch mal int n?
</code></pre>
<p>meinst du das ich int n = 0 zweimal habe? Habe es oben entfernt, jetzt bringt jedoch der Compiler Fehler Overload.</p>
<p>Denke es liegt an der pow() Funktion aber weiß nicht wie ich das ändern sollte/ könnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2177497</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177497</guid><dc:creator><![CDATA[Scriptlaie]]></dc:creator><pubDate>Mon, 06 Feb 2012 09:47:52 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 10:07:52 GMT]]></title><description><![CDATA[<p>Keine Ahnung was du mit deinem Compiler anstellst und welchen du nutzt.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cmath&gt;  // c++ Header in C++ Quelltext
</code></pre>
<p>Ich denke mal das hast du missverstanden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Im formatierten Quelltext siehst du ja die Zeilennummern <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Den Ausgabefehler baust du dir in Zeile 24 + 25 <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>Nimm mal Papier und Schreiber und versuche nach zu vollziehen was du machst und vergleiche das mit dem was du gern hättest.</p>
<p>MfG f.-th.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2177507</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177507</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Mon, 06 Feb 2012 10:07:52 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 10:41:34 GMT]]></title><description><![CDATA[<p>Vielen Dank für deine Hilfe f.-th.!!!!</p>
<p>Habe es geschafft.</p>
<p>Mal schauen wann ich wieder mal etwas brauche.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2177525</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177525</guid><dc:creator><![CDATA[Scriptlaie]]></dc:creator><pubDate>Mon, 06 Feb 2012 10:41:34 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 14:18:36 GMT]]></title><description><![CDATA[<p>C++ ist übrigens keine Scriptsprache, falls du das nicht weißt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2177593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177593</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 06 Feb 2012 14:18:36 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Umwandlung Dualsystem in Dezimalsystem on Mon, 06 Feb 2012 15:31:03 GMT]]></title><description><![CDATA[<p>Hier nochmal ne Variante, weil mir gerad langweilig ist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

int DualString2Int(std::string p_sDual)
{
	int iReturn=0;
	for(size_t s=0;s&lt;p_sDual.substr(0, 32).length();s++)
	{
		iReturn = (iReturn &lt;&lt; 1);
		iReturn|= p_sDual[s]=='1'?1:0;
	}
	return iReturn;
}

int main()
{
	std::string InputData;

	std::cout&lt;&lt;&quot;Geben Sie eine maximal 32-stellige Zahl auf Basis 2 ein \noder q um das Programm zu beenden: &quot;;
	while(std::getline(std::cin, InputData))
	{
		if(Data==&quot;q&quot;)break;

		std::cout&lt;&lt;&quot;\nDezimalzahl: &quot;&lt;&lt;DualString2Int(InputData)&lt;&lt;&quot;\n\nZahl auf Basis 2 [q zum Beenden]: &quot;;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2177636</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2177636</guid><dc:creator><![CDATA[Hobo]]></dc:creator><pubDate>Mon, 06 Feb 2012 15:31:03 GMT</pubDate></item></channel></rss>