<?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[erste beiden bits eines unsigned long?]]></title><description><![CDATA[<p>Hi,<br />
wie kann ich gucken, ob die ersten beiden bits (linke Seite) eines unsigned long gesetzt sind?</p>
<p>Danke...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/137617/erste-beiden-bits-eines-unsigned-long</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 19:41:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/137617.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Feb 2006 10:14:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to erste beiden bits eines unsigned long? on Sun, 19 Feb 2006 10:14:36 GMT]]></title><description><![CDATA[<p>Hi,<br />
wie kann ich gucken, ob die ersten beiden bits (linke Seite) eines unsigned long gesetzt sind?</p>
<p>Danke...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/997643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/997643</guid><dc:creator><![CDATA[:D]]></dc:creator><pubDate>Sun, 19 Feb 2006 10:14:36 GMT</pubDate></item><item><title><![CDATA[Reply to erste beiden bits eines unsigned long? on Sun, 19 Feb 2006 10:24:34 GMT]]></title><description><![CDATA[<p>mit der entspr. zhal und verkn. und erg. anschauen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/997652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/997652</guid><dc:creator><![CDATA[e geben Sie einen Benutze]]></dc:creator><pubDate>Sun, 19 Feb 2006 10:24:34 GMT</pubDate></item><item><title><![CDATA[Reply to erste beiden bits eines unsigned long? on Sun, 19 Feb 2006 10:33:22 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">unsigned long l=0xFFFFFFFF;
	if (l &amp; (1&lt;&lt;(sizeof(long)*8-1)) | (1&lt;&lt;(sizeof(long)*8-2)) )
		//gesetzt
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/997662</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/997662</guid><dc:creator><![CDATA[Cpt. Tanga]]></dc:creator><pubDate>Sun, 19 Feb 2006 10:33:22 GMT</pubDate></item><item><title><![CDATA[Reply to erste beiden bits eines unsigned long? on Sun, 19 Feb 2006 10:53:03 GMT]]></title><description><![CDATA[<p>edit:</p>
<pre><code class="language-cpp">if ( ( l &amp; (1&lt;&lt;sizeof(long)*8-1) ) &amp;&amp; ( l &amp; (1&lt;&lt;sizeof(long)*8-2) ) )
        //gesetzt
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/997681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/997681</guid><dc:creator><![CDATA[Cpt. Tanga]]></dc:creator><pubDate>Sun, 19 Feb 2006 10:53:03 GMT</pubDate></item><item><title><![CDATA[Reply to erste beiden bits eines unsigned long? on Sun, 19 Feb 2006 11:12:24 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> schrieb:</p>
<blockquote>
<p>Hi,<br />
wie kann ich gucken, ob die ersten beiden bits (linke Seite) eines unsigned long gesetzt sind?</p>
</blockquote>
<p>Aus 'linke Seite' folgere ich, dass Du die beiden hochwertigsten Bits meinst; also z.B. Bit 30 und Bit 31, falls ein unsigned long 4 Byte lang ist.<br />
Folgendes sollte funktionieren, auch wenn sizeof( unsigend long ) &gt; sizeof( int ) ist.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
    using namespace std;
    const unsigned long HighBits2 = ( static_cast&lt; unsigned long &gt;( 3 ) &lt;&lt; (8 * sizeof( unsigned long ) - 2) );
    for( unsigned long l; cout &lt;&lt; &quot;&gt; &quot;, cin &gt;&gt; l; )
    {
        cout &lt;&lt; &quot;Eingabe in Hex-Code: &quot; &lt;&lt; hex &lt;&lt; l &lt;&lt; dec &lt;&lt; endl;
        if( (l &amp; HighBits2) == HighBits2 ) // &lt;-- hier ist die Abfrage
        {
            cout &lt;&lt; &quot;die beiden hochwertigsten Bits sind gesetzt.&quot; &lt;&lt; endl;
        }
    }
    return 0;
}
</code></pre>
<p>Wenn Du dagegen definitiv Bit 30 | Bit 31 abfragen willst, unabhänig davon, wie lang ein unsigned long ist, so schreibe besser:</p>
<pre><code class="language-cpp">const unsigned long HighBits2 = 0xC0000000;  // Bit 30 | Bit 31
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/997699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/997699</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sun, 19 Feb 2006 11:12:24 GMT</pubDate></item><item><title><![CDATA[Reply to erste beiden bits eines unsigned long? on Sun, 19 Feb 2006 11:18:14 GMT]]></title><description><![CDATA[<p>Ich würde es wie folgt probieren:</p>
<pre><code class="language-cpp">unsigned long x = /*...*/;
bool result = (x &amp; (3lu &lt;&lt; sizeof(unsigned long) * CHAR_BIT - 2)) == (3lu &lt;&lt; sizeof(unsigned long) * CHAR_BIT - 2);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/997701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/997701</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Sun, 19 Feb 2006 11:18:14 GMT</pubDate></item></channel></rss>