<?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[Bitmaskierung bei Bitshifting]]></title><description><![CDATA[<p>Weshalb werden bei diesem Makro die einzelnen Bytes mit 0xff maskiert vor dem shift?</p>
<pre><code class="language-cpp">#define D3DCOLOR_ARGB(a,r,g,b)   ((D3DCOLOR)((((a)&amp;0xff)&lt;&lt;24)|(((r)&amp;0xff)&lt;&lt;16)|(((g)&amp;0xff)&lt;&lt;8)|((b)&amp;0xff)))
</code></pre>
<p>Und kann ich aus einer 32Bit Variable die 4 Komponenten so herauslesen, wenn sie als ARGB gespeichert sind?</p>
<pre><code class="language-cpp">Color( unsigned int argb )
{
	unsigned char *p = reinterpret_cast&lt; unsigned char* &gt;( &amp;argb );
	Alpha = p[ 3 ];
	Red   = p[ 2 ];
	Green = p[ 1 ];
	Blue  = p[ 0 ];
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/122866/bitmaskierung-bei-bitshifting</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 08:06:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/122866.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 10 Oct 2005 20:27:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bitmaskierung bei Bitshifting on Mon, 10 Oct 2005 20:27:55 GMT]]></title><description><![CDATA[<p>Weshalb werden bei diesem Makro die einzelnen Bytes mit 0xff maskiert vor dem shift?</p>
<pre><code class="language-cpp">#define D3DCOLOR_ARGB(a,r,g,b)   ((D3DCOLOR)((((a)&amp;0xff)&lt;&lt;24)|(((r)&amp;0xff)&lt;&lt;16)|(((g)&amp;0xff)&lt;&lt;8)|((b)&amp;0xff)))
</code></pre>
<p>Und kann ich aus einer 32Bit Variable die 4 Komponenten so herauslesen, wenn sie als ARGB gespeichert sind?</p>
<pre><code class="language-cpp">Color( unsigned int argb )
{
	unsigned char *p = reinterpret_cast&lt; unsigned char* &gt;( &amp;argb );
	Alpha = p[ 3 ];
	Red   = p[ 2 ];
	Green = p[ 1 ];
	Blue  = p[ 0 ];
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/889218</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/889218</guid><dc:creator><![CDATA[C++er]]></dc:creator><pubDate>Mon, 10 Oct 2005 20:27:55 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmaskierung bei Bitshifting on Mon, 10 Oct 2005 20:54:46 GMT]]></title><description><![CDATA[<p>C++er schrieb:</p>
<blockquote>
<p>Weshalb werden bei diesem Makro die einzelnen Bytes mit 0xff maskiert vor dem shift?</p>
</blockquote>
<p>Weil Makros im Gegensatz zu Funktionen dumm sind und keine Typprüfung erlauben. Wer hindert dich daran, bei diesem Makro Werte zu benutzen, die über 255 hinausgehen?</p>
<blockquote>
<p>Und kann ich aus einer 32Bit Variable die 4 Komponenten so herauslesen, wenn sie als ARGB gespeichert sind?</p>
</blockquote>
<p>Warum probierst du es nicht aus? Auf einer Little-Endian-Plattform sollte das aber funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/889236</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/889236</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Mon, 10 Oct 2005 20:54:46 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmaskierung bei Bitshifting on Tue, 11 Oct 2005 07:52:47 GMT]]></title><description><![CDATA[<p>Warum kehrst du nicht einfach die Arbeit des obigen Makros um?</p>
<pre><code class="language-cpp">Alpha = (col &gt;&gt; 24) &amp; 0xFF;
Red   = (col &gt;&gt; 16) &amp; 0xFF;
Green = (col &gt;&gt; 8 ) &amp; 0xFF;
Blue  = (col      ) &amp; 0xFF;
</code></pre>
<p>Das sollte auf jeden Fall funktionieren, egal wie ein int gespeichert ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/889351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/889351</guid><dc:creator><![CDATA[CS]]></dc:creator><pubDate>Tue, 11 Oct 2005 07:52:47 GMT</pubDate></item></channel></rss>