<?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[Verhalten des bitshift (&amp;lt;&amp;lt;,&amp;gt;&amp;gt;) Operators]]></title><description><![CDATA[<p>Hallo allerseits,</p>
<p>wie ist folgendes Verhalten des bitshift Operators zu erklären:</p>
<p>a) unter Matlab ergibt (-7&lt;&lt;1) --&gt; -14, alles klar<br />
b) unter C++ ergibt (-7&lt;&lt;1) --&gt; -14, alles klar<br />
c) unter Matlab ergibt (-7&gt;&gt;1) --&gt; -3, alles klar<br />
d) unter C++ ergibt (-7&gt;&gt;1) --&gt; -4, warum das?</p>
<p>Kann mir das jemand erklären? Ich weiß, dass das hier ein C++ Forum ist und meine Frage nicht direkt was mit den Eigenschaften von C++ zu tun. Wusste aber nicht, wo das ganze sonst rein sollte. Man möge mir das verzeihen.</p>
<p>Viele Grüße,<br />
mbu</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/240780/verhalten-des-bitshift-lt-lt-gt-gt-operators</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 19:59:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/240780.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 May 2009 15:13:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verhalten des bitshift (&amp;lt;&amp;lt;,&amp;gt;&amp;gt;) Operators on Mon, 11 May 2009 15:14:23 GMT]]></title><description><![CDATA[<p>Hallo allerseits,</p>
<p>wie ist folgendes Verhalten des bitshift Operators zu erklären:</p>
<p>a) unter Matlab ergibt (-7&lt;&lt;1) --&gt; -14, alles klar<br />
b) unter C++ ergibt (-7&lt;&lt;1) --&gt; -14, alles klar<br />
c) unter Matlab ergibt (-7&gt;&gt;1) --&gt; -3, alles klar<br />
d) unter C++ ergibt (-7&gt;&gt;1) --&gt; -4, warum das?</p>
<p>Kann mir das jemand erklären? Ich weiß, dass das hier ein C++ Forum ist und meine Frage nicht direkt was mit den Eigenschaften von C++ zu tun. Wusste aber nicht, wo das ganze sonst rein sollte. Man möge mir das verzeihen.</p>
<p>Viele Grüße,<br />
mbu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709051</guid><dc:creator><![CDATA[mbu]]></dc:creator><pubDate>Mon, 11 May 2009 15:14:23 GMT</pubDate></item><item><title><![CDATA[Reply to Verhalten des bitshift (&amp;lt;&amp;lt;,&amp;gt;&amp;gt;) Operators on Mon, 11 May 2009 15:33:28 GMT]]></title><description><![CDATA[<p>-7 &gt;&gt; 1 gibts in Matlab nicht, meinst du bitshift(-7, -1)? Dazu die Hilfe:</p>
<blockquote>
<p>C = BITSHIFT(A,K) returns the value of A shifted by K bits. A must be<br />
an unsigned integer or an array of unsigned integers.</p>
</blockquote>
<p>Matlabs Verhalten würde ich nicht als Maßstab heranziehen.</p>
<p>In C++ ist das Rechtsschieben von negativen Werten <em>implementation-defined</em>. Die wesentliche Frage dabei ist, ob beim Rechtsschieben negativer Zahlen von links Nullen oder Einsen hereingeschoben werden, also ob das Schieben logisch oder arithmetisch ist. Der Standard schreibt es nicht vor.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709064</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 11 May 2009 15:33:28 GMT</pubDate></item><item><title><![CDATA[Reply to Verhalten des bitshift (&amp;lt;&amp;lt;,&amp;gt;&amp;gt;) Operators on Mon, 11 May 2009 15:50:15 GMT]]></title><description><![CDATA[<p>Ja, ich im Matlab Fall meinte ich bitshift(-7,-1). Ich hab den Hilfeeintrag da auch gelesen, hab mich nur gewundert, dass dann bei Nutzung von -7 keine Fehlermeldung oder eigenartige Ergebnisse rauskommen.</p>
<p>Was den C/C++ Fall betrifft, muss ich dann wohl auf den Bitshift bei negativen Werten verzichten. Irgendwie scheint mir -7&gt;&gt;1=-4 nämlich nicht wirklich logisch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709077</guid><dc:creator><![CDATA[mbu]]></dc:creator><pubDate>Mon, 11 May 2009 15:50:15 GMT</pubDate></item><item><title><![CDATA[Reply to Verhalten des bitshift (&amp;lt;&amp;lt;,&amp;gt;&amp;gt;) Operators on Mon, 11 May 2009 16:03:19 GMT]]></title><description><![CDATA[<p>Mal der Einfachheit halber mit 8 Bit Wortbreite dargestellt: -7 ist in binär 11111001, das um 1 nach rechts geshiftet unter Beibehaltung des Vorzeichens: 11111100, dezimal -4. Bei einem logischen Shift wäre 01111100 herausgekommen, also 124. Bei der üblichen Zweierkomplementdarstellung kann man gar nicht auf -3 kommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709081</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709081</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 11 May 2009 16:03:19 GMT</pubDate></item><item><title><![CDATA[Reply to Verhalten des bitshift (&amp;lt;&amp;lt;,&amp;gt;&amp;gt;) Operators on Mon, 11 May 2009 16:16:10 GMT]]></title><description><![CDATA[<p>Ja, da hast Du natürlich vollkommen Recht. Danke Dir nochmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709087</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709087</guid><dc:creator><![CDATA[mbu]]></dc:creator><pubDate>Mon, 11 May 2009 16:16:10 GMT</pubDate></item></channel></rss>