<?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[unsigend char negieren]]></title><description><![CDATA[<p>Huhu,<br />
kann mir jemand erklären, wieso bei ...</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main()
{
	unsigned char c = 0;
	cout &lt;&lt; ~c; // ... -1 rauskommt, und nicht 255?

	return 0;
}
</code></pre>
<p>Danke im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/299411/unsigend-char-negieren</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 07:57:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/299411.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 10 Feb 2012 13:42:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to unsigend char negieren on Fri, 10 Feb 2012 13:42:11 GMT]]></title><description><![CDATA[<p>Huhu,<br />
kann mir jemand erklären, wieso bei ...</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main()
{
	unsigned char c = 0;
	cout &lt;&lt; ~c; // ... -1 rauskommt, und nicht 255?

	return 0;
}
</code></pre>
<p>Danke im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2179380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2179380</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 10 Feb 2012 13:42:11 GMT</pubDate></item><item><title><![CDATA[Reply to unsigend char negieren on Fri, 10 Feb 2012 13:52:33 GMT]]></title><description><![CDATA[<p>ISO/IEC 5.3.1 (9) schrieb:</p>
<blockquote>
<p>The operand of ~ shall have integral or enumeration type; the result is the one’s complement of its operand. <strong>Integral promotions are performed.</strong> The type of the result is the type of the promoted operand. (...)</p>
</blockquote>
<p>Im Ausdruck ~c wird c zunächst werterhaltend in einen int umgewandelt, und dessen Bits werden dann umgekehrt. Das Ergebnis ist vom Typ int.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2179385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2179385</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Fri, 10 Feb 2012 13:52:33 GMT</pubDate></item><item><title><![CDATA[Reply to unsigend char negieren on Fri, 10 Feb 2012 13:54:11 GMT]]></title><description><![CDATA[<p>Das sind die arkanen Regeln der &quot;integral promotion&quot;. Das c wird vor dem Berechnen von ~ in einen int umgewandelt, ~0 ist -1 und das Ergebnis ist dann auch vom Typ int und wird entsprechend ausgegeben.</p>
<p>edit: Zu langsam.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2179387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2179387</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 10 Feb 2012 13:54:11 GMT</pubDate></item><item><title><![CDATA[Reply to unsigend char negieren on Fri, 10 Feb 2012 15:55:11 GMT]]></title><description><![CDATA[<p>Ach, natürlich. Bin gerade selbst drauf gekommen. Bevor die Operation <code>~</code> gemacht wird, wird <code>uc</code> ja zu <code>int</code> promoted. Und int i = 0 negiert ist nunmal -1.</p>
<p>edit: ;), Danke euch trotzdem. <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/2179389</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2179389</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 10 Feb 2012 15:55:11 GMT</pubDate></item><item><title><![CDATA[Reply to unsigend char negieren on Fri, 10 Feb 2012 14:05:09 GMT]]></title><description><![CDATA[<p>Gugelmoser schrieb:</p>
<blockquote>
<p>Und int i = 0 negiert ist nunmal -1.</p>
</blockquote>
<p>0 negiert ist 0.</p>
<p>Und der Wert von ~0 muss auch nicht -1 sein (Zweierkomplement), er kann auch -0 (Einerkomplement) oder INT_MIN sein (Sign+Magnitude).</p>
<p>Das Ergebnis von Bitoperationen auf vorzeichenbehafteten Ganzzahlen ist implementierungsabhängig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2179397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2179397</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Fri, 10 Feb 2012 14:05:09 GMT</pubDate></item><item><title><![CDATA[Reply to unsigend char negieren on Fri, 10 Feb 2012 14:06:37 GMT]]></title><description><![CDATA[<p>Und wenn das nicht so wäre, würde auch nicht 255 raus kommen, sondern das entsprechende Ascii-Zeichen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2179400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2179400</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Fri, 10 Feb 2012 14:06:37 GMT</pubDate></item></channel></rss>