<?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[w &amp;amp;= 0xfffffffc]]></title><description><![CDATA[<p>Hallo,<br />
bin neu hier und hoffe hier Hilfe zu finden. Versuche im Gegenzug natürlich auch zu helfen, wenn ich kann. Aber nun zu meinem Problem:</p>
<p>In einem Sourcecode bin ich über folgende kleine Methode gestolpert:</p>
<pre><code>void TruncateWidth(int&amp; w)
{
   w &amp;= 0xfffffffc;
}
</code></pre>
<p>Es handelt sich beim übergebenen 'w' um eine Referenz auf die Breite eines geladenen Bildes. Was macht nun der '&amp;='-Operator mit dieser Referenz?<br />
Bei einem Aufruf der Methode hat sich bisher nichts am mitgegebenem Wert geändert. Wann wäre dem denn nicht so?<br />
Schonmal vielen Dank im voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/249566/w-amp-0xfffffffc</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 11:10:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/249566.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Sep 2009 08:59:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 08:59:05 GMT]]></title><description><![CDATA[<p>Hallo,<br />
bin neu hier und hoffe hier Hilfe zu finden. Versuche im Gegenzug natürlich auch zu helfen, wenn ich kann. Aber nun zu meinem Problem:</p>
<p>In einem Sourcecode bin ich über folgende kleine Methode gestolpert:</p>
<pre><code>void TruncateWidth(int&amp; w)
{
   w &amp;= 0xfffffffc;
}
</code></pre>
<p>Es handelt sich beim übergebenen 'w' um eine Referenz auf die Breite eines geladenen Bildes. Was macht nun der '&amp;='-Operator mit dieser Referenz?<br />
Bei einem Aufruf der Methode hat sich bisher nichts am mitgegebenem Wert geändert. Wann wäre dem denn nicht so?<br />
Schonmal vielen Dank im voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775042</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775042</guid><dc:creator><![CDATA[gnuaquin]]></dc:creator><pubDate>Wed, 09 Sep 2009 08:59:05 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 09:08:46 GMT]]></title><description><![CDATA[<p>Die Funktion löscht die unteren beiden Bits.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775057</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775057</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Wed, 09 Sep 2009 09:08:46 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 09:13:26 GMT]]></title><description><![CDATA[<p>Jup. Und zur Erklärung:</p>
<p>0xfffffffc = 11111111111111111111111111111100 in Binärschreibweise</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775066</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775066</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 09 Sep 2009 09:13:26 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 09:16:45 GMT]]></title><description><![CDATA[<p>wenn ich nicht ganz falsch liege könnte man sagen das statement macht w durch 4 teilbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775068</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775068</guid><dc:creator><![CDATA[jperl]]></dc:creator><pubDate>Wed, 09 Sep 2009 09:16:45 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 09:20:21 GMT]]></title><description><![CDATA[<p>Vielen Dank für die schnelle Hilfe.<br />
Habe mich bisher nie wirklich mit den Bit-Operatoren beschäftigt.<br />
Sie ersparen zwar Schreibarbeit, machen den Code aber (für mich) unübersichtlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775071</guid><dc:creator><![CDATA[gnuaquin]]></dc:creator><pubDate>Wed, 09 Sep 2009 09:20:21 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 09:29:08 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void TruncateWidth(unsigned&amp; w)
{
   w -= w % 4;
}
</code></pre>
<p>erzeugt den gleichen Code, wenn der Compiler was taugt. Beachte die Verwendung von unsigned hier, denn bei negativen ints ist das Ergebnis des and (bei 2er Komplement) nicht durch 4 teilbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775079</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 09 Sep 2009 09:29:08 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 09:34:05 GMT]]></title><description><![CDATA[<p>Sieht auf jeden Fall übersichtlicher aus.<br />
Da w die Breite eines Bildes angibt, sollten negative Werte ausgeschlossen werden. Daher ist unsigned natürlich auch eine gute Idee.<br />
Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775082</guid><dc:creator><![CDATA[gnuaquin]]></dc:creator><pubDate>Wed, 09 Sep 2009 09:34:05 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 09:35:02 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<pre><code class="language-cpp">void TruncateWidth(unsigned&amp; w)
{
   w -= w % 4;
}
</code></pre>
<p>erzeugt den gleichen Code, wenn der Compiler was taugt. Beachte die Verwendung von unsigned hier, denn bei negativen ints ist das Ergebnis des and (bei 2er Komplement) nicht durch 4 teilbar.</p>
</blockquote>
<p>hm ok stimmt, daran habe ich gar nicht gedacht.<br />
bin aufgrund der breitenangabe eines bildes von positiven werten ausgegangen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775084</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775084</guid><dc:creator><![CDATA[jperl]]></dc:creator><pubDate>Wed, 09 Sep 2009 09:35:02 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 09:38:16 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<pre><code class="language-cpp">void TruncateWidth(unsigned&amp; w)
{
   w -= w % 4;
}
</code></pre>
<p>erzeugt den gleichen Code, wenn der Compiler was taugt.</p>
</blockquote>
<pre><code class="language-cpp">void TruncateWidth (unsigned&amp; w)
{
   w = (w&gt;&gt;2)&lt;&lt;2;
}
</code></pre>
<p>erzeugt den gleichen Code, wenn der Compiler was taugt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775088</guid><dc:creator><![CDATA[C++Fan 2009]]></dc:creator><pubDate>Wed, 09 Sep 2009 09:38:16 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 11:20:43 GMT]]></title><description><![CDATA[<p>C++Fan 2009 schrieb:</p>
<blockquote>
<p>camper schrieb:</p>
<blockquote>
<pre><code class="language-cpp">void TruncateWidth(unsigned&amp; w)
{
   w -= w % 4;
}
</code></pre>
<p>erzeugt den gleichen Code, wenn der Compiler was taugt.</p>
</blockquote>
<pre><code class="language-cpp">void TruncateWidth (unsigned&amp; w)
{
   w = (w&gt;&gt;2)&lt;&lt;2;
}
</code></pre>
<p>erzeugt den gleichen Code, wenn der Compiler was taugt.</p>
</blockquote>
<p>Bei <code>unsigned</code> kann man ja wieder ohne Bedenken bzgl Portabilität</p>
<pre><code class="language-cpp">void TruncateWidth (unsigned &amp; w)
{
   return w &amp; -4;
}
</code></pre>
<p>schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775176</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775176</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Wed, 09 Sep 2009 11:20:43 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 12:14:29 GMT]]></title><description><![CDATA[<p>Jetzt, wo ich verstehe was da abläuft, kann ich's ja so lassen.<br />
Aber vielen Dank an Alle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775219</guid><dc:creator><![CDATA[gnuaquin]]></dc:creator><pubDate>Wed, 09 Sep 2009 12:14:29 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 12:24:02 GMT]]></title><description><![CDATA[<p>Sebastian Pizer schrieb:</p>
<blockquote>
<p>Bei <code>unsigned</code> kann man ja wieder ohne Bedenken bzgl Portabilität</p>
<pre><code class="language-cpp">void TruncateWidth (unsigned &amp; w)
{
   return w &amp; -4;
}
</code></pre>
<p>schreiben.</p>
</blockquote>
<p>bloß das</p>
<pre><code class="language-cpp">void TruncateWidth (unsigned &amp; w)
</code></pre>
<p>keinen rückgabewert hat...<br />
sry für [klugscheiß].</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775224</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775224</guid><dc:creator><![CDATA[Keithy]]></dc:creator><pubDate>Wed, 09 Sep 2009 12:24:02 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 12:39:32 GMT]]></title><description><![CDATA[<p>Keithy schrieb:</p>
<blockquote>
<p>Sebastian Pizer schrieb:</p>
<blockquote>
<p>Bei <code>unsigned</code> kann man ja wieder ohne Bedenken bzgl Portabilität</p>
<pre><code class="language-cpp">void TruncateWidth (unsigned &amp; w)
{
   return w &amp; -4;
}
</code></pre>
<p>schreiben.</p>
</blockquote>
<p>bloß das</p>
<pre><code class="language-cpp">void TruncateWidth (unsigned &amp; w)
</code></pre>
<p>keinen rückgabewert hat...<br />
sry für [klugscheiß].</p>
</blockquote>
<p>Richtig. Ich hatte es zwischendurch zu einer Funktion a la<br />
<code>unsigned TruncateWidth (unsigned w)</code><br />
geändert und dann nur zur Hälfte wieder zurück. So muss es natürlich<br />
<code>w &amp;= -4;</code><br />
heißen.</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775235</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Wed, 09 Sep 2009 12:39:32 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 12:44:37 GMT]]></title><description><![CDATA[<p>Sebastian Pizer schrieb:</p>
<blockquote>
<p>Bei <code>unsigned</code> kann man ja wieder ohne Bedenken bzgl Portabilität</p>
<pre><code class="language-cpp">void TruncateWidth (unsigned &amp; w)
{
   return w &amp; -4;
}
</code></pre>
<p>schreiben.</p>
</blockquote>
<p>wieso? muss -4 auf jedem system dieser erde 0xfffffffc sein?<br />
<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>
]]></description><link>https://www.c-plusplus.net/forum/post/1775240</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775240</guid><dc:creator><![CDATA[Basher_ist_nicht_BashAr]]></dc:creator><pubDate>Wed, 09 Sep 2009 12:44:37 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 12:55:39 GMT]]></title><description><![CDATA[<p>Basher schrieb:</p>
<blockquote>
<p>wieso? muss -4 auf jedem system dieser erde 0xfffffffc sein?<br />
<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>
</blockquote>
<p>Das nicht, aber es wird ja implizit zu einem unsigned konvertiert, bevor &amp; angewendet wird. unsigned(-4) liefert garantiert eine vorzeichenlose Zahl mit Bitmuster &quot;11...1100&quot; -- auch, wenn Du einen Exoten hast, der für vorzeichenbehaftete Ganzzahlen <em>nicht</em> das 2er-Komplement benutzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775245</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775245</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Wed, 09 Sep 2009 12:55:39 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 12:58:38 GMT]]></title><description><![CDATA[<p>Sebastian Pizer schrieb:</p>
<blockquote>
<p>Basher schrieb:</p>
<blockquote>
<p>wieso? muss -4 auf jedem system dieser erde 0xfffffffc sein?<br />
<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>
</blockquote>
<p>Das nicht, aber es wird ja implizit zu einem unsigned konvertiert, bevor &amp; angewendet wird. unsigned(-4) liefert garantiert eine vorzeichenlose Zahl mit Bitmuster &quot;11...1100&quot;.</p>
</blockquote>
<p>wenn nun aber für negative zahlen kein zweier-, sondern z.b. einerkomplement benutzt wird (sowas solls ja geben), dann ist -4 111...1011. damit löschste nur bit 2 weg, nicht bit 1 und 0, wie geplant.<br />
btw, noch 'ne variante:</p>
<pre><code>unsigned TruncateWidth (unsigned w)
{
   return (w/4)*4;
}
</code></pre>
<p><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>
]]></description><link>https://www.c-plusplus.net/forum/post/1775253</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775253</guid><dc:creator><![CDATA[Basher_ist_nicht_BashAr]]></dc:creator><pubDate>Wed, 09 Sep 2009 12:58:38 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 13:01:33 GMT]]></title><description><![CDATA[<p>Basher schrieb:</p>
<blockquote>
<p>wenn nun aber für negative zahlen kein zweier-, sondern z.b. einerkomplement benutzt wird (sowas solls ja geben), dann ist -4 111...1011.</p>
</blockquote>
<p>Spielt keine Rolle. Der C++ Standard sagt genau, was passiert, wenn Du eine vorzeichenbehaftete Zahl zu einer vorzeichenlosen Zahl konvertierst. Das Bitmuster, was Du danach erhälst entspricht <em>immer</em> dem 2er-Komplement.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775258</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775258</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Wed, 09 Sep 2009 13:01:33 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 13:28:06 GMT]]></title><description><![CDATA[<p>Sebastian Pizer schrieb:</p>
<blockquote>
<p>Der C++ Standard sagt genau, was passiert, wenn Du eine vorzeichenbehaftete Zahl zu einer vorzeichenlosen Zahl konvertierst. Das Bitmuster, was Du danach erhälst entspricht <em>immer</em> dem 2er-Komplement.</p>
</blockquote>
<p>biste sicher? was passiert bei:</p>
<pre><code class="language-cpp">// angenommen: negative zahlen sind einerkomplement, 'signed magnitude' oder was anderes
unsigned a = (unsigned)-4;  // &lt;-- a enthält jetzt bitmuster von -4 im zweierkomplement, nach deiner aussage
int b = (int)a; // bekommen wir hier unsere -4 zurück? wohl kaum.
</code></pre>
<p><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>
]]></description><link>https://www.c-plusplus.net/forum/post/1775287</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775287</guid><dc:creator><![CDATA[Basher_ist_nicht_BashAr]]></dc:creator><pubDate>Wed, 09 Sep 2009 13:28:06 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 13:39:29 GMT]]></title><description><![CDATA[<p>Basher schrieb:</p>
<blockquote>
<p>biste sicher?</p>
</blockquote>
<p>Ja. Soll ich jetzt noch die Stelle aus dem Standard raussuchen? Müste irgendwo bei &quot;standard conversions&quot; sein. Das mit dem Bitmuster ergibt sich aus der Regel, dass bei &quot;u=s;&quot; -- wobei u eine <em>vorzeichenlose</em> Integervariable und s irgend eine andere Integervariable (meinetwegen auch long) ist -- folgendes gilt:<br />
u = s modulo (2 hoch N), N ist hier die Zahl der Bits in u.</p>
<p>Basher schrieb:</p>
<blockquote>
<p>was passiert bei:</p>
<pre><code class="language-cpp">// angenommen: negative zahlen sind einerkomplement, 'signed magnitude'
// oder was anderes
unsigned a = (unsigned)-4;  // &lt;-- a enthält jetzt bitmuster von
                            // -4 im zweierkomplement, nach deiner aussage
int b = (int)a; // bekommen wir hier unsere -4 zurück? wohl kaum.
</code></pre>
</blockquote>
<p>Nein. Konvertieren in eine vorzeichenbehaftete Zahl ist &quot;implementation-defined&quot;, falls der zugewiesene Wert nicht im Wertebereich liegt. Steht auch so im Standard. Guck mal selbst nach. :p</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775289</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775289</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Wed, 09 Sep 2009 13:39:29 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 13:37:48 GMT]]></title><description><![CDATA[<p>msvc++</p>
<p>ohne probleme kommt da -4 raus. bitmuster bei beiden: 0xfffffffc</p>
<p><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>
]]></description><link>https://www.c-plusplus.net/forum/post/1775294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775294</guid><dc:creator><![CDATA[helferlein]]></dc:creator><pubDate>Wed, 09 Sep 2009 13:37:48 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 13:41:42 GMT]]></title><description><![CDATA[<p>Für meinen Geschmack ist das diese Variante (x &amp; -4u) ein bisschen zu subtil, auch wenn ich zugeben muss, dass ich das früher auch so geschrieben habe.<br />
x &amp; ~(4u-1) ist vielleicht ein bisschen besser. Bei heutigen Compilern gibt es aber eigentlich nur noch selten einen Grund, das im Code stehen zu lassen.<br />
Sowas hab ich in der Wildnis auch schon gesehen:</p>
<pre><code class="language-cpp">int foo;
while ( foo % 4 != 0 )
    foo--;
</code></pre>
<p>Da ziehe ich dann sogar ein einfaches &amp; vor <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1775295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775295</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 09 Sep 2009 13:41:42 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 13:44:55 GMT]]></title><description><![CDATA[<p>Sebastian Pizer schrieb:</p>
<blockquote>
<p>Das mit dem Bitmuster ergibt sich aus der Regel, dass bei &quot;u=s;&quot; -- wobei u eine <em>vorzeichenlose</em> Integervariable und s irgend eine andere Integervariable (meinetwegen auch long) ist -- folgendes gilt:<br />
u = s modulo (2 hoch N), N ist hier die Zahl der Bits in u.</p>
</blockquote>
<p>das glaube ich dir, aber das daraus in jedem fall ein zweierkomplement wird, egal mit welcher kodierung ein system negative zahlen speichert, kann ich mir nicht vorstellen.</p>
<p>helferlein schrieb:</p>
<blockquote>
<p>msvc++<br />
ohne probleme kommt da -4 raus. bitmuster bei beiden: 0xfffffffc</p>
</blockquote>
<p>wir reden hier von 'nicht-zweierkomplement' systemen.</p>
<p>camper schrieb:</p>
<blockquote>
<p>Für meinen Geschmack ist das diese Variante (x &amp; -4u) ein bisschen zu subtil...</p>
</blockquote>
<p>finde ich auch.<br />
<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>
]]></description><link>https://www.c-plusplus.net/forum/post/1775302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775302</guid><dc:creator><![CDATA[Basher_ist_nicht_BashAr]]></dc:creator><pubDate>Wed, 09 Sep 2009 13:44:55 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 14:04:45 GMT]]></title><description><![CDATA[<p>da wir jetzt alle 1000 tricks kennen, die unteren zwei bits zu löschen, mal andersrum: wie kommt man am schnellsten auf das nächste <em>grössere</em> vielfache von 4? bitte, postet eure vorschläge....<br />
<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>
]]></description><link>https://www.c-plusplus.net/forum/post/1775319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775319</guid><dc:creator><![CDATA[Basher_ist_nicht_BashAr]]></dc:creator><pubDate>Wed, 09 Sep 2009 14:04:45 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 14:04:50 GMT]]></title><description><![CDATA[<p>Basher schrieb:</p>
<blockquote>
<p>Sebastian Pizer schrieb:</p>
<blockquote>
<p>Das mit dem Bitmuster ergibt sich aus der Regel, dass bei &quot;u=s;&quot; -- wobei u eine <em>vorzeichenlose</em> Integervariable und s irgend eine andere Integervariable (meinetwegen auch long) ist -- folgendes gilt:<br />
u = s modulo (2 hoch N), N ist hier die Zahl der Bits in u.</p>
</blockquote>
<p>das glaube ich dir, aber das daraus in jedem fall ein zweierkomplement wird, egal mit welcher kodierung ein system negative zahlen speichert, kann ich mir nicht vorstellen.</p>
</blockquote>
<p>Das folgt <em>direkt</em> aus der Modulo-Regel.</p>
<pre><code>//   2er-K           1er-K           Sign+Mag
int      s = -10;  //   111...11110110  111...11110101  100...00001010

                   //  1000...00000000  (2^N)
                   // - 000...00001010  (10)
                   //  ---------------
unsigned u = s;    //   111...11110110  (2^N - 10 = -10 mod 2^N)
</code></pre>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775320</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Wed, 09 Sep 2009 14:04:50 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 14:06:56 GMT]]></title><description><![CDATA[<p>Basher schrieb:</p>
<blockquote>
<p>da wir jetzt alle 1000 tricks kennen, die unteren zwei bits zu löschen, mal andersrum: wie kommt man am schnellsten auf das nächste <em>grössere</em> vielfache von 4? bitte, postet eure vorschläge....</p>
</blockquote>
<p>Ich nehme an, dass falls die Zahl schon durch 4 teilbar ist, dass sie dann nicht verändert werden soll.</p>
<pre><code class="language-cpp">inline unsigned aufrunden(unsigned x)
{
  return (x+3) &amp; unsigned(-4);
}
</code></pre>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775323</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775323</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Wed, 09 Sep 2009 14:06:56 GMT</pubDate></item><item><title><![CDATA[Reply to w &amp;amp;= 0xfffffffc on Wed, 09 Sep 2009 15:11:36 GMT]]></title><description><![CDATA[<p>Sebastian Pizer schrieb:</p>
<blockquote>
<pre><code>//   2er-K           1er-K           Sign+Mag
int      s = -10;  //   111...11110110  111...11110101  100...00001010

                   //  1000...00000000  (2^N)
                   // - 000...00001010  (10)
                   //  ---------------
unsigned u = s;    //   111...11110110  (2^N - 10 = -10 mod 2^N)
</code></pre>
</blockquote>
<p>ok, das sieht überzeugend aus (obwohl nicht das 'mod', also % benutzt wird, was wir in C so haben).</p>
<p>Sebastian Pizer schrieb:</p>
<blockquote>
<p>Basher schrieb:</p>
<blockquote>
<p>da wir jetzt alle 1000 tricks kennen, die unteren zwei bits zu löschen, mal andersrum: wie kommt man am schnellsten auf das nächste <em>grössere</em> vielfache von 4? bitte, postet eure vorschläge....</p>
</blockquote>
<p>Ich nehme an, dass falls die Zahl schon durch 4 teilbar ist, dass sie dann nicht verändert werden soll.</p>
</blockquote>
<p>ja, und 0 soll auch 0 bleiben. noch mehr vorschläge?<br />
<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>
]]></description><link>https://www.c-plusplus.net/forum/post/1775391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775391</guid><dc:creator><![CDATA[Basher_ist_nicht_BashAr]]></dc:creator><pubDate>Wed, 09 Sep 2009 15:11:36 GMT</pubDate></item></channel></rss>