<?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[Dezimalzahl in Binärdarstellung]]></title><description><![CDATA[<p>Habe mal ein Programm geschrieben, das eine einfache Dezimalzahl in Binärform umwandelt. Kommt aber keine Ausgabe und ich finde einfach nicht den Fehler.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
using namespace std;

int main() {
	int eingabe,temp,y;
	cin &gt;&gt; eingabe;

	for(int x=1;x&lt;eingabe;x++){
		if(eingabe&lt;=pow(2,x))
			y=x;
	}

	for(int x=y;x&gt;=0;x--){
		if(pow(2,y)&lt;=eingabe){
			eingabe=eingabe-(pow(2,y));
			temp=1;
		}
		else temp=0;

		cout &lt;&lt; temp;
	}
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/195944/dezimalzahl-in-binärdarstellung</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 07:05:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/195944.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Oct 2007 18:44:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Wed, 24 Oct 2007 04:51:43 GMT]]></title><description><![CDATA[<p>Habe mal ein Programm geschrieben, das eine einfache Dezimalzahl in Binärform umwandelt. Kommt aber keine Ausgabe und ich finde einfach nicht den Fehler.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;
using namespace std;

int main() {
	int eingabe,temp,y;
	cin &gt;&gt; eingabe;

	for(int x=1;x&lt;eingabe;x++){
		if(eingabe&lt;=pow(2,x))
			y=x;
	}

	for(int x=y;x&gt;=0;x--){
		if(pow(2,y)&lt;=eingabe){
			eingabe=eingabe-(pow(2,y));
			temp=1;
		}
		else temp=0;

		cout &lt;&lt; temp;
	}
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1390769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390769</guid><dc:creator><![CDATA[M4ST0R]]></dc:creator><pubDate>Wed, 24 Oct 2007 04:51:43 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Tue, 23 Oct 2007 19:03:35 GMT]]></title><description><![CDATA[<p>Schau mal in die FAQ<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39490.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39490.html</a><br />
dann nach unten scrollen...</p>
<pre><code class="language-cpp">template &lt;unsigned int NrOfBits&gt;
string DezToBin(int Wert)
{
    bitset&lt;NrOfBits&gt; AlsBits(Wert);
    return AlsBits.to_string();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1390781</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390781</guid><dc:creator><![CDATA[mtaesler]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:03:35 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Tue, 23 Oct 2007 19:05:06 GMT]]></title><description><![CDATA[<p>Das habe ich bereits gesehen.</p>
<p>Mir geht es aber darum, dass mein Programm geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390783</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390783</guid><dc:creator><![CDATA[M4ST0R]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:05:06 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Tue, 23 Oct 2007 19:12:09 GMT]]></title><description><![CDATA[<blockquote>
<p>Habe mal ein Programm geschrieben, das eine einfache Dualzahl in Binärform umwandelt.</p>
</blockquote>
<p>Ist Dual und binär nicht das gleiche?</p>
<blockquote>
<p>Kommt aber keine Ausgabe und ich finde einfach nicht den Fehler.</p>
</blockquote>
<p>Kommt eine Fehlermeldung oder schließt einfach die konsole? 2. -&gt; Konsolen FAQ</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390793</guid><dc:creator><![CDATA[trallallla]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:12:09 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Tue, 23 Oct 2007 19:30:15 GMT]]></title><description><![CDATA[<blockquote>
<p>Ist Dual und binär nicht das gleiche?</p>
</blockquote>
<p>Jap. Binär und Dual bezeichnen beide das 2er System. Wir rechnen normalerweise im 10er System, d.h. dem Dezimalsystem.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390813</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:30:15 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Tue, 23 Oct 2007 19:38:45 GMT]]></title><description><![CDATA[<p>Meine auch das Dezimalsystem. Tut mir leid für das Missverständnis <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>
<p>Bei meinem Programm gebe ich eine Zahl ein die in 'eingabe' gelesen wird, aber es kommt nichts raus. Am Ende kommt nur &lt;terminated&gt; blabla.exe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390823</guid><dc:creator><![CDATA[M4ST0R]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:38:45 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Tue, 23 Oct 2007 19:40:19 GMT]]></title><description><![CDATA[<p>Was er damit sagen will ist , das das Dezimale eine Basis von 10 hat und Ziffern von 0-9 und das Dualsystem hat eine Basis von 2 und hat nur die Ziffern 0 oder 1 die einen Zustand beschreiben .. Hehe.. kenn mich um DUalsystem (subtrahieren,addieren etc) nur so gut aus weil wir das heute gerade in Digitaltechnik hatten und ich man was besser wissen wollte als (D)Evil xD</p>
<p>MFG TOa</p>
<p>Edit : Mist zu spätz^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390825</guid><dc:creator><![CDATA[Toa]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:40:19 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Tue, 23 Oct 2007 21:49:49 GMT]]></title><description><![CDATA[<p>M4ST0R schrieb:</p>
<blockquote>
<p>Das habe ich bereits gesehen.</p>
<p>Mir geht es aber darum, dass mein Programm geht.</p>
</blockquote>
<p>Der erste Teil - die Berechnung von y - ist bereits falsch. Du musst die Schleife abbrechen, wenn ein x erreicht ist wobei 2^x &gt; eingabe ist. Grob korrigiert so</p>
<pre><code class="language-cpp">int y = 1;
    for( int x=1; ; ++x ){
        if( eingabe &lt; pow(2,x) )
            break;  // Abbruch da 2^x jetzt größer als die Eingabe ist.
        y = x; // 2^x ist noch &lt;= eingabe; also x in y merken
    }
</code></pre>
<p>Im zweiten Teil hast Du einfach x und y verwechselt. Da wo pow(2,y) steht, ist pow(2,x) richtig.</p>
<p>Ein Tipp: verzichte auf die Funktion pow() und bestimme die Zahl 2^x durch wiederholtes multiplizieren mit 2. Die Suche nach dem richtigen y sähe dann so aus:</p>
<pre><code class="language-cpp">int y = 0;
    for( int x=2; ; x*=2 ){
        if( eingabe &lt; x )
            break;  // Abbruch da 2^x jetzt größer als die Eingabe ist.
        ++y;        // nach ++y gilt 2^y == x
    }
    // 2^y ist jetzt die größte Zahl der Form 2^x, 
    //  die kleiner oder gleich der eingabe ist.
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390897</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 23 Oct 2007 21:49:49 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Wed, 24 Oct 2007 04:48:34 GMT]]></title><description><![CDATA[<p>Vielen dank Werner, das hat mir sehr geholfen. Mein Programm funktioniert nun wunderbar.</p>
<p>Bei der 2. Schleife die du angegeben hast müsste y=1 sein, da wir x=2 zuweisen. Ansonsten ist alles in Ordnung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390917</guid><dc:creator><![CDATA[M4ST0R]]></dc:creator><pubDate>Wed, 24 Oct 2007 04:48:34 GMT</pubDate></item><item><title><![CDATA[Reply to Dezimalzahl in Binärdarstellung on Wed, 24 Oct 2007 21:27:17 GMT]]></title><description><![CDATA[<p>M4ST0R schrieb:</p>
<blockquote>
<p>Bei der 2. Schleife die du angegeben hast müsste y=1 sein, da wir x=2 zuweisen.</p>
</blockquote>
<p>Ich hatte es ausprobiert. Mit y=1 als Startwert wird die Binärzahl mit einer führenden '0' ausgegeben. Ich meine y=0 ist korrekt.<br />
Wenn die Eingabe ==0 oder ==1 ist, so bleibt y=0 stehen und wird nicht inkrementiert. Dann wird die untere Schleife genau einmal durchlaufen und genau eine (Binär-)Stelle ausgegeben. Was ja auch ok ist.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1391539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1391539</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 24 Oct 2007 21:27:17 GMT</pubDate></item></channel></rss>