<?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[Bit Verschiebung]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein unsigned char bar [4]<br />
und da ist ein Wert gespeichert, die vier drei Byte und ein Bit lang ist also 33 Bit. Nun möchte ich das das wert um sieben stellen nach links verschoben wird also sozusagen bar = bar &lt;&lt;7<br />
Wie kann ich das realisieren</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/254896/bit-verschiebung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 06:59:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/254896.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 22 Nov 2009 22:23:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bit Verschiebung on Sun, 22 Nov 2009 22:23:53 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein unsigned char bar [4]<br />
und da ist ein Wert gespeichert, die vier drei Byte und ein Bit lang ist also 33 Bit. Nun möchte ich das das wert um sieben stellen nach links verschoben wird also sozusagen bar = bar &lt;&lt;7<br />
Wie kann ich das realisieren</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812055</guid><dc:creator><![CDATA[borhany]]></dc:creator><pubDate>Sun, 22 Nov 2009 22:23:53 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Sun, 22 Nov 2009 22:28:42 GMT]]></title><description><![CDATA[<p>reinterpret_cast!?</p>
<p>so in etwa:</p>
<pre><code class="language-cpp">char foo[4];
//foo = ...
*reinterpret_cast&lt;long*&gt;(foo) &lt;&lt;= 7;
</code></pre>
<p>zumindest die idee dahinter sollte klar werden^^</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812057</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812057</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 22 Nov 2009 22:28:42 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Sun, 22 Nov 2009 22:38:00 GMT]]></title><description><![CDATA[<p>Danke für dein Antwor, das habe ich mir auch gedacht und schon ausprobiert, aber es funktioniert leider nicht<br />
also wenn man es mit Das wert in Foo = 1 ist dann ja wenn aber das wert z.B. 0xababab1 sein sollte dann funktioniert es leider nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812061</guid><dc:creator><![CDATA[borhany]]></dc:creator><pubDate>Sun, 22 Nov 2009 22:38:00 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Sun, 22 Nov 2009 22:44:00 GMT]]></title><description><![CDATA[<p>borhany schrieb:</p>
<blockquote>
<p>also 33 Bit.</p>
</blockquote>
<p>Nein, 3*8+1 sind 25 Bit. Und 0xababab1 ist breiter als 25 Bit, dementsprechend kann der Shift bei Verwendung eines 32-Bit-Typs nicht klappen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812065</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812065</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Sun, 22 Nov 2009 22:44:00 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Sun, 22 Nov 2009 22:54:41 GMT]]></title><description><![CDATA[<p>stimmt, dumm von mir habe es mit</p>
<pre><code>crc32 = 0xababab1&lt;&lt;7;
unsigned char bar[5]={(crc32 &gt;&gt; 32) &amp; 0xFF,  (crc32 &gt;&gt; 24) &amp; 0xFF , (crc32 &gt;&gt; 16) &amp; 0xFF, (crc32 &gt;&gt; 8) &amp; 0xFF, (crc32 &gt;&gt; 0) &amp; 0xFF  };
</code></pre>
<p>probiert funktioniert immer leider noch nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812067</guid><dc:creator><![CDATA[borhany]]></dc:creator><pubDate>Sun, 22 Nov 2009 22:54:41 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Mon, 23 Nov 2009 00:07:25 GMT]]></title><description><![CDATA[<p>Wenn schon, dann:</p>
<pre><code class="language-cpp">char foo[8];
*reinterpret_cast&lt;uint64_t*&gt;(foo)=0xbababa1;
*reinterpret_cast&lt;uint64_t*&gt;(foo) &lt;&lt;= 7;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1812076</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812076</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Mon, 23 Nov 2009 00:07:25 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Mon, 23 Nov 2009 09:45:36 GMT]]></title><description><![CDATA[<p>borhany schrieb:</p>
<blockquote>
<p>ich habe ein unsigned char bar [4]</p>
</blockquote>
<p>ok soweit</p>
<p>borhany schrieb:</p>
<blockquote>
<p>und da ist ein Wert gespeichert, die vier drei Byte und ein Bit lang ist also 33 Bit.</p>
</blockquote>
<p><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=":confused:"
      alt="😕"
    /> Wieviel Bytes und Bits? Wie?</p>
<p>borhany schrieb:</p>
<blockquote>
<p>Nun möchte ich das das wert um sieben stellen nach links verschoben wird also sozusagen bar = bar &lt;&lt;7</p>
</blockquote>
<p>Was heißt denn das? Beschreib mal, gib Beispiele, <a href="http://de.wikipedia.org/wiki/ASCII-Art" rel="nofollow">mal's auf</a> in einem code-block. Wie ordnest Du die Bits an?</p>
<p>Wofür braucht man das? Könnte mir vorstellen, dass Du einfach nur zu kompliziert denkst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812158</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812158</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Mon, 23 Nov 2009 09:45:36 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Mon, 23 Nov 2009 10:24:47 GMT]]></title><description><![CDATA[<p>Sorry, ich meinte 33Bit ist richtig also $ BYte und ein Bit<br />
wieso unsigned char foo [8]<br />
in fünf Byte müsste doch das wert auch passen. oder stört unsigned</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812185</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812185</guid><dc:creator><![CDATA[borhany]]></dc:creator><pubDate>Mon, 23 Nov 2009 10:24:47 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Mon, 23 Nov 2009 18:36:07 GMT]]></title><description><![CDATA[<p>Der nächstgrößte Datentyp nach 32 Bit ist bei meinem Compiler eben 64 Bit, deswegen 8 Bytes. Wenn dein Compiler 40 Bit-Typen unterstützt, kannst du natürlich auch die nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812528</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812528</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Mon, 23 Nov 2009 18:36:07 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Mon, 23 Nov 2009 18:50:37 GMT]]></title><description><![CDATA[<p>Man könnte natürlich auch einfach rechnen, dann wäre es auch portabel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812543</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812543</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 23 Nov 2009 18:50:37 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Mon, 23 Nov 2009 23:35:17 GMT]]></title><description><![CDATA[<p>Mit rechnen habe ich es ausprobiert. Also bei kleinen Werten muss ich es mal 128 und bei großen 128. Ich weiss immer noch nicht wo mein fehler liegt<br />
Das kann ja so nicht richtig sein</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812678</guid><dc:creator><![CDATA[borhany]]></dc:creator><pubDate>Mon, 23 Nov 2009 23:35:17 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Mon, 23 Nov 2009 23:45:50 GMT]]></title><description><![CDATA[<p>borhany schrieb:</p>
<blockquote>
<p>Mit rechnen habe ich es ausprobiert. Also bei kleinen Werten muss ich es mal 128 und bei großen 128. Ich weiss immer noch nicht wo mein fehler liegt<br />
Das kann ja so nicht richtig sein</p>
</blockquote>
<p>Ich verstehe den Satz nicht, in dem du beschreibst, was du gemacht hast.</p>
<p>Grob gesagt muss man bei einem 8 Bit char: Den ersten char 7 Bits nach links verschieben. Vom zweiten char die 7 höchstwertigen Bits nehmen. Diese um 1 Bit nach rechts schieben. Das Ergebnis mit dem verschobenem ersten char logisch &amp; verknüpfen.<br />
Genauso fortfahren mit dem zweiten char.</p>
<p>Das kann man natürlich auch für chars, die nicht 8 Bits haben, verallgemeinern. In &lt;limits&gt; steht drin, wie viele Bits ein char hat. Möglicherweise kann man das auch nochmal vereinfachen, aber so müsste das auf jeden Fall gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812679</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 23 Nov 2009 23:45:50 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Tue, 24 Nov 2009 08:40:43 GMT]]></title><description><![CDATA[<p>borhany schrieb:</p>
<blockquote>
<p>...Ich weiss immer noch nicht wo mein fehler liegt...</p>
</blockquote>
<p>Der Fehler liegt darin, dass Du Deine Postings nicht noch einmal durchliest, bevor Du sie abschickst. Ist nicht böse gemeint, aber um helfen zu können, muss man schon verstehen was Du genau willst. Mit halbfertigen Satzfragmenten ohne Punkt und Komma ist das allerdings schwierig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812740</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812740</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Tue, 24 Nov 2009 08:40:43 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Tue, 24 Nov 2009 09:09:44 GMT]]></title><description><![CDATA[<p>borhany schrieb:</p>
<blockquote>
<p>Mit rechnen habe ich es ausprobiert. Also bei kleinen Werten muss ich es mal 128 und bei großen 128. Ich weiss immer noch nicht wo mein fehler liegt<br />
Das kann ja so nicht richtig sein</p>
</blockquote>
<p>Bahnhof.</p>
<p>Du hast es immer noch nicht geschafft zu beschreiben, was Du eigentlich willst. Viel zu wenig Information von Deiner Seite aus! Shit in, shit out! Wenn Du Deine Frage nicht präzise formulierst, wirst Du einen großen Anteil an Antworten mit Code bekommen, der nicht das macht, was Du willst.</p>
<p>borhany schrieb:</p>
<blockquote>
<p>sozusagen bar = bar &lt;&lt; 7</p>
</blockquote>
<p>Der Shift-Operator ist natürlich nicht auf Arrays definiert, nur auf Ganzzahltypen. Und bei Ganzzahltypen ist klar, was sie machen. Du versuchst hier zu beschreiben, was Du willst, lässt aber ein entscheidendes Detail weg. Du reduzierst ein &quot;Array shift&quot; auf ein &quot;Ganzzahl shift&quot;, verrätst aber nicht wie man von dem char[] zu einer Ganzzahl kommt und dann wieder zurück. Stichwort: Byte-Ordnung.</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812758</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Tue, 24 Nov 2009 09:09:44 GMT</pubDate></item><item><title><![CDATA[Reply to Bit Verschiebung on Tue, 24 Nov 2009 09:23:23 GMT]]></title><description><![CDATA[<p>borhany schrieb:</p>
<blockquote>
<p>habe es mit</p>
<pre><code>crc32 = 0xababab1&lt;&lt;7;
  unsigned char bar[5]={(crc32 &gt;&gt; 32) &amp; 0xFF,  (crc32 &gt;&gt; 24) &amp; 0xFF , (crc32 &gt;&gt; 16) &amp; 0xFF, (crc32 &gt;&gt; 8) &amp; 0xFF, (crc32 &gt;&gt; 0) &amp; 0xFF  };
</code></pre>
<p>probiert, funktioniert immer leider noch nicht</p>
</blockquote>
<p>Was funktioniert da nicht?! Inwiefern unterscheidet sich das Ergebnis von dem, was Du haben willst? <em>Ich</em> kann zumindest <em>nicht hellsehen</em>.</p>
<p>Wenn Du Hilfe willst, musst Du Dir schon mehr Mühe geben! Vielleicht solltest Du auch mehr von dem drumherum verraten, also, warum Du glaubst, so etwas machen zu müssen. Wenn Du eine CRC-Prüfsumme berechnen willst: Das geht auch viel eleganter.</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1812763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1812763</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Tue, 24 Nov 2009 09:23:23 GMT</pubDate></item></channel></rss>