<?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[Integer in Zweierkomplement umwandeln]]></title><description><![CDATA[<p>Hallo allerseits</p>
<p>Ich habe mal eine Frage. Ich bräuchte ein Stück Programmcode, dass eine Integerzahl ins Zweierkomplement (meinetwegen als String) umwandelt.</p>
<p>Mir persönlich fällt nur die &quot;Schulmethode&quot; ein, danach müsste ich aber die Bits alle umdrehen und dann auf einem String +1 rechnen, was zumindest nicht unaufwendig wird...</p>
<p>Daher die Frage, ob jmd. eine effektivere Methode kennt...</p>
<p>Danke schonmal</p>
<p>Mit freundlichen Gruß</p>
<p>Soul</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/225026/integer-in-zweierkomplement-umwandeln</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 21:11:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/225026.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 18 Oct 2008 09:58:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Integer in Zweierkomplement umwandeln on Sat, 18 Oct 2008 09:58:46 GMT]]></title><description><![CDATA[<p>Hallo allerseits</p>
<p>Ich habe mal eine Frage. Ich bräuchte ein Stück Programmcode, dass eine Integerzahl ins Zweierkomplement (meinetwegen als String) umwandelt.</p>
<p>Mir persönlich fällt nur die &quot;Schulmethode&quot; ein, danach müsste ich aber die Bits alle umdrehen und dann auf einem String +1 rechnen, was zumindest nicht unaufwendig wird...</p>
<p>Daher die Frage, ob jmd. eine effektivere Methode kennt...</p>
<p>Danke schonmal</p>
<p>Mit freundlichen Gruß</p>
<p>Soul</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1600725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1600725</guid><dc:creator><![CDATA[Soul83]]></dc:creator><pubDate>Sat, 18 Oct 2008 09:58:46 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in Zweierkomplement umwandeln on Sat, 18 Oct 2008 10:43:09 GMT]]></title><description><![CDATA[<p>Hallo Soul83,</p>
<p>da afaik jeder gängige Rechner das Zweierkomplement verwendet, kannst du sowas<br />
auch etwa so machen: (ungetestet!!!)</p>
<pre><code class="language-cpp">signed int i = -9999;
unsigned int bit = 1 &lt;&lt; (sizeof(unsigned int)*8-1);
while(bit){// Solange das Bit nicht durchgelaufen ist und folglich bit != 0 
	if(i ^ bit) // Wenn das Bit gesetzt...
		std::cout &lt;&lt; &quot;1&quot;;
	else
		std::cout &lt;&lt; &quot;0&quot;;
	bit = bit &gt;&gt; 1;
}
</code></pre>
<p>Analog kannste das natürlich auch in einen String schreiben.</p>
<p>Gruß,<br />
CSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1600742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1600742</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 18 Oct 2008 10:43:09 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in Zweierkomplement umwandeln on Sat, 18 Oct 2008 10:45:05 GMT]]></title><description><![CDATA[<p>schau mal im C++-Buch deiner wahl nach dem Komplement-operator <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/1600746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1600746</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Sat, 18 Oct 2008 10:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in Zweierkomplement umwandeln on Sat, 18 Oct 2008 11:16:47 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9960">@pumuckl</a>: der Komplement-operator hilft mir in dem Fall leider nicht weiter...</p>
<p>@spille: gute Idee, klappt aber leider nicht...er schreibt nur 1er in den Stream <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1600758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1600758</guid><dc:creator><![CDATA[Soul83]]></dc:creator><pubDate>Sat, 18 Oct 2008 11:16:47 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in Zweierkomplement umwandeln on Sat, 18 Oct 2008 11:34:11 GMT]]></title><description><![CDATA[<p>Dann versuch doch mal:</p>
<p>if(i &amp; bit) // Wenn das Bit gesetzt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1600766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1600766</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Sat, 18 Oct 2008 11:34:11 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in Zweierkomplement umwandeln on Sat, 18 Oct 2008 11:36:47 GMT]]></title><description><![CDATA[<p>ups...</p>
<p>Man sollte auch kein exklusives-Oder nehmen ^^</p>
<p>Versuch es mal damit:</p>
<pre><code class="language-cpp">if(i&amp;bit)
</code></pre>
<p>Gruß,<br />
CSpille</p>
<p>EDIT: Ok... Belli war schneller <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/1600768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1600768</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 18 Oct 2008 11:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in Zweierkomplement umwandeln on Sat, 18 Oct 2008 11:40:18 GMT]]></title><description><![CDATA[<p>Oh, das sieht gut aus... mir war nicht ganz klar, wie die if-Anweisung das AND or XOR interpretiert ... jetzt ist klar...</p>
<p>Danke euch</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1600773</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1600773</guid><dc:creator><![CDATA[Soul83]]></dc:creator><pubDate>Sat, 18 Oct 2008 11:40:18 GMT</pubDate></item><item><title><![CDATA[Reply to Integer in Zweierkomplement umwandeln on Sat, 18 Oct 2008 14:53:40 GMT]]></title><description><![CDATA[<p>Warum gibt es eigentlich kein <code>std::bin</code> (also analog zu <code>std::hex</code> )? Wird das zu wenig gebraucht, als dass die Implementation sich gelohnt hätte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1600840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1600840</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sat, 18 Oct 2008 14:53:40 GMT</pubDate></item></channel></rss>