<?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[Binär Dezimal-Zahl vergleichen? [gelöst]]]></title><description><![CDATA[<p>Hallo,</p>
<p>wie kann ich eine Dezimal-Zahl binär oder ähnlich Prüfen?</p>
<p>Folgendes Beispiel dazu: Ein Auftrag befindet sich in einem Status (oder auch mehrere):</p>
<p>0 = neuer Auftrag<br />
1 = Ware auf Lager<br />
2 = Ware bestellt<br />
4 = Ware angefragt<br />
8 = Ware abgerufen<br />
16 = Ware gesendet<br />
32 = Rechnungsprüfung<br />
64 = Rücklieferung<br />
128 = Mahnung<br />
256 = Auftrag abgeschlossen</p>
<p>Wenn die Ware gesendet wurde (16) und eine Rechnungsprüfung (32) erforderlich ist, befindet sich der Auftrag in dem Status 48. Wie kann ich jetzt Prüfen ob eine bestimmte Position (z.B. Rechnungsprüfung) dem Auftrag zugeordnet ist?</p>
<pre><code>if( (16 in 48 enthalten) == true )
{
   mache irgendetwas...
}
</code></pre>
<p>Wie geht das?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/264016/binär-dezimal-zahl-vergleichen-gelöst</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 09:38:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/264016.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 Mar 2010 12:39:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Binär Dezimal-Zahl vergleichen? [gelöst] on Sat, 17 Apr 2010 08:03:02 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>wie kann ich eine Dezimal-Zahl binär oder ähnlich Prüfen?</p>
<p>Folgendes Beispiel dazu: Ein Auftrag befindet sich in einem Status (oder auch mehrere):</p>
<p>0 = neuer Auftrag<br />
1 = Ware auf Lager<br />
2 = Ware bestellt<br />
4 = Ware angefragt<br />
8 = Ware abgerufen<br />
16 = Ware gesendet<br />
32 = Rechnungsprüfung<br />
64 = Rücklieferung<br />
128 = Mahnung<br />
256 = Auftrag abgeschlossen</p>
<p>Wenn die Ware gesendet wurde (16) und eine Rechnungsprüfung (32) erforderlich ist, befindet sich der Auftrag in dem Status 48. Wie kann ich jetzt Prüfen ob eine bestimmte Position (z.B. Rechnungsprüfung) dem Auftrag zugeordnet ist?</p>
<pre><code>if( (16 in 48 enthalten) == true )
{
   mache irgendetwas...
}
</code></pre>
<p>Wie geht das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1875953</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1875953</guid><dc:creator><![CDATA[Sharpie]]></dc:creator><pubDate>Sat, 17 Apr 2010 08:03:02 GMT</pubDate></item><item><title><![CDATA[Reply to Binär Dezimal-Zahl vergleichen? [gelöst] on Wed, 31 Mar 2010 12:43:21 GMT]]></title><description><![CDATA[<p>Der Compiler wandelt automatisch in Binaerzahlen um. Mache dir die Zahlen im Binaerformat deutlich, verwende ein bitweises (und).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1875956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1875956</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 31 Mar 2010 12:43:21 GMT</pubDate></item><item><title><![CDATA[Reply to Binär Dezimal-Zahl vergleichen? [gelöst] on Wed, 31 Mar 2010 12:45:20 GMT]]></title><description><![CDATA[<p>Mit bitweisen Operatoren.</p>
<pre><code class="language-cpp">int status=0;
status|=0x1;  //Bit 1 setzen
status|=0x4;  //Bit 3 setzen

if(status &amp; (1&lt;&lt;1) {
  std::cout &lt;&lt; &quot;Bit 1 gesetzt&quot; &lt;&lt; std::endl;
}
if(status &amp; (1&lt;&lt;2) {
  std::cout &lt;&lt; &quot;Bit 2 gesetzt&quot; &lt;&lt; std::endl;
}
if(status &amp; (1&lt;&lt;3) {
  std::cout &lt;&lt; &quot;Bit 3 gesetzt&quot; &lt;&lt; std::endl;
}
</code></pre>
<p>Schau dir besser mal ganz genau die Doku zu den verwendeten Operatoren an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1875957</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1875957</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Wed, 31 Mar 2010 12:45:20 GMT</pubDate></item><item><title><![CDATA[Reply to Binär Dezimal-Zahl vergleichen? [gelöst] on Wed, 31 Mar 2010 12:46:12 GMT]]></title><description><![CDATA[<p>Ist jetzt aus der Python-Konsole, aber funktionieren tut das in C++ identisch:</p>
<pre><code class="language-cpp">&gt;&gt;&gt; stat = 1 | 4 | 16
&gt;&gt;&gt; stat &amp; 1
1
&gt;&gt;&gt; stat &amp; 2
0
&gt;&gt;&gt; stat &amp; 4
4
&gt;&gt;&gt; stat &amp; 8
0
&gt;&gt;&gt; stat &amp; 16
16
&gt;&gt;&gt; stat &amp; 32
0
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1875958</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1875958</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or]]></dc:creator><pubDate>Wed, 31 Mar 2010 12:46:12 GMT</pubDate></item><item><title><![CDATA[Reply to Binär Dezimal-Zahl vergleichen? [gelöst] on Wed, 31 Mar 2010 13:29:19 GMT]]></title><description><![CDATA[<p>Das verstehe ich nicht so ganz, denn ich erhalte folgendes Ergebnis:</p>
<pre><code class="language-cpp">int status=0;
	status|=0x1;  //Bit 1 setzen
	//status|=0x4;  //Bit 2 setzen
	//status|=0x8;  //Bit 3 setzen
	status|=0x16; //Bit 4 setzen

	if(status &amp; (1&lt;&lt;0)) {
		qDebug() &lt;&lt; &quot;Bit 1 gesetzt&quot;;
		//OK
	}
	if(status &amp; (1&lt;&lt;1)) {
		qDebug() &lt;&lt; &quot;Bit 2 gesetzt&quot;;
		//OK
	}
	if(status &amp; (1&lt;&lt;2)) {
		qDebug() &lt;&lt; &quot;Bit 3 gesetzt&quot;;
		//OK
	}
	if(status &amp; (1&lt;&lt;3)) {
		qDebug() &lt;&lt; &quot;Bit 4 gesetzt&quot;;
		//NOK
	}
	if(status &amp; (1&lt;&lt;4)) {
		qDebug() &lt;&lt; &quot;Bit 5 gesetzt&quot;;
		//OK
	}
</code></pre>
<p>Jetzt sollte aber nur, Bit 1 und Bit 4 OK sein! Verstehe ich da etwas falsch und wie funktioniert dass was ich möchte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1875971</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1875971</guid><dc:creator><![CDATA[Sharpie]]></dc:creator><pubDate>Wed, 31 Mar 2010 13:29:19 GMT</pubDate></item><item><title><![CDATA[Reply to Binär Dezimal-Zahl vergleichen? [gelöst] on Wed, 31 Mar 2010 13:32:10 GMT]]></title><description><![CDATA[<p>Sharpie schrieb:</p>
<blockquote>
<p>status|=0x16; //Bit 4 setzen</p>
</blockquote>
<p>Schau Dir die Zeile nochmal an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1875973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1875973</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Wed, 31 Mar 2010 13:32:10 GMT</pubDate></item><item><title><![CDATA[Reply to Binär Dezimal-Zahl vergleichen? [gelöst] on Wed, 31 Mar 2010 13:34:34 GMT]]></title><description><![CDATA[<p>0x16 ist eine hexadezimale Angabe und nicht gleich dezimal 16 (es ist 22)!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1875976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1875976</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Wed, 31 Mar 2010 13:34:34 GMT</pubDate></item><item><title><![CDATA[Reply to Binär Dezimal-Zahl vergleichen? [gelöst] on Sat, 17 Apr 2010 08:02:23 GMT]]></title><description><![CDATA[<p>Vielen Dank, an alle! Ich hab es verstanden, es funktioniert jetzt:</p>
<pre><code class="language-cpp">int status=0;
    status|=0x1;  //Bit 1 setzen
    status|=0x2;  //Bit 2 setzen
    status|=0x4;  //Bit 3 setzen

    if(status &amp; (1&lt;&lt;0)) {
        qDebug() &lt;&lt; &quot;Bit 1 gesetzt&quot;;
    }
    if(status &amp; (1&lt;&lt;1)) {
        qDebug() &lt;&lt; &quot;Bit 2 gesetzt&quot;;
     }
    if(status &amp; (1&lt;&lt;2)) {
        qDebug() &lt;&lt; &quot;Bit 3 gesetzt&quot;;
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1884141</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1884141</guid><dc:creator><![CDATA[Sharpie]]></dc:creator><pubDate>Sat, 17 Apr 2010 08:02:23 GMT</pubDate></item></channel></rss>