<?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[Datastream]]></title><description><![CDATA[<p>Hallo Zusammen!</p>
<p>Ich hab folgendes Problem:<br />
Ich habe einen Buffer mit verschiedenen Werten drin:</p>
<pre><code>Buffer[] = {3,9,4,5...}
</code></pre>
<p>Diese geben die Anzahl 1 oder 0 an welche ich in einen Datastream umwandeln muss. Also:<br />
z.B</p>
<pre><code>Buffer[0]=3
</code></pre>
<p>Ob es nun drei 1 oder drei 0 sind ist im Moment egal. Sagen wir einfach es sind drei 1.<br />
Der Datastream ist 8 bit lang und ist auch ein Buffer.<br />
Also:</p>
<pre><code>Datastream[] = {111xxxxx}
               {xxxxxxxx}
               ...
</code></pre>
<p>Ich habe keine Ahnung wie ich das realisieren soll, denn die Werte welche im Buffer stehen, können alle länger als 8 sein.<br />
Weiss jemand wie ich hier vorgehen könnte? Vielen Dank. <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/topic/325292/datastream</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 20:51:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325292.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 24 Apr 2014 12:58:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Datastream on Thu, 24 Apr 2014 12:58:08 GMT]]></title><description><![CDATA[<p>Hallo Zusammen!</p>
<p>Ich hab folgendes Problem:<br />
Ich habe einen Buffer mit verschiedenen Werten drin:</p>
<pre><code>Buffer[] = {3,9,4,5...}
</code></pre>
<p>Diese geben die Anzahl 1 oder 0 an welche ich in einen Datastream umwandeln muss. Also:<br />
z.B</p>
<pre><code>Buffer[0]=3
</code></pre>
<p>Ob es nun drei 1 oder drei 0 sind ist im Moment egal. Sagen wir einfach es sind drei 1.<br />
Der Datastream ist 8 bit lang und ist auch ein Buffer.<br />
Also:</p>
<pre><code>Datastream[] = {111xxxxx}
               {xxxxxxxx}
               ...
</code></pre>
<p>Ich habe keine Ahnung wie ich das realisieren soll, denn die Werte welche im Buffer stehen, können alle länger als 8 sein.<br />
Weiss jemand wie ich hier vorgehen könnte? Vielen Dank. <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/2396110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396110</guid><dc:creator><![CDATA[Messinho]]></dc:creator><pubDate>Thu, 24 Apr 2014 12:58:08 GMT</pubDate></item><item><title><![CDATA[Reply to Datastream on Thu, 24 Apr 2014 13:28:46 GMT]]></title><description><![CDATA[<p>Ich hab ehrlich gesagt keine Ahnung was du da vorhast. <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="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396118</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 24 Apr 2014 13:28:46 GMT</pubDate></item><item><title><![CDATA[Reply to Datastream on Thu, 24 Apr 2014 13:41:49 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Ich hab ehrlich gesagt keine Ahnung was du da vorhast. <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="😕"
    /></p>
</blockquote>
<p>Also wenn ich zum Beispiel im Buffer solche Werte habe:<br />
3,2,9,4,6,8...<br />
dann soll im anderen Buffer (Datastream) das gepeichert werden:</p>
<pre><code>Datastream[0]= 11100111
Datastream[1]= 11111100
Datastream[2]= 00111111
Datastream[3]= 00000000
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2396119</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396119</guid><dc:creator><![CDATA[Messinho]]></dc:creator><pubDate>Thu, 24 Apr 2014 13:41:49 GMT</pubDate></item><item><title><![CDATA[Reply to Datastream on Thu, 24 Apr 2014 13:42:12 GMT]]></title><description><![CDATA[<p>Messinho schrieb:</p>
<blockquote>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Ich hab ehrlich gesagt keine Ahnung was du da vorhast. <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="😕"
    /></p>
</blockquote>
<p>Also wenn ich zum Beispiel im Buffer solche Werte habe:<br />
3,2,9,4,6,8...<br />
dann soll im anderen Buffer (Datastream) das gespeichert werden:</p>
<pre><code>Datastream[0]= 11100111
Datastream[1]= 11111100
Datastream[2]= 00111111
Datastream[3]= 00000000
</code></pre>
</blockquote>
<p>drei mal ne 1, dann 2 mal ne 0, dann 9 mal ne 1 etc.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396121</guid><dc:creator><![CDATA[Messinho]]></dc:creator><pubDate>Thu, 24 Apr 2014 13:42:12 GMT</pubDate></item><item><title><![CDATA[Reply to Datastream on Thu, 24 Apr 2014 13:55:57 GMT]]></title><description><![CDATA[<p>Also quasi immer abwechselnd?</p>
<p>Naja, sagen wir mal dir reichen als Zielwerte 0 oder 1, dann kannst du den boolschen Datentyp nehmen.</p>
<p>Ich würde dann zuerst anfangen mir einen Vector durchgehend zu befüllen und den danach in eine gewünschte Größe aufsplitten.</p>
<p>Etwa so:</p>
<pre><code>int Buffer[] = {3, 2, 9, 4 /*...*/};

std::vector&lt;bool&gt; tempStream;

// Stream füllen
bool val = true;
for(int i : Buffer)
{
	tempStream.insert(std::end(tempStream), i, val);
	val = !val;
}

// DataStream erzeugen durch splitten des Streams
int chunksize = 8;
std::vector&lt;std::vector&lt;bool&gt;&gt; datastream;
for(int i = 0; i &lt; tempStream.size(); i +=chunksize)
{
	std::vector&lt;bool&gt; tmp;
	for(int j = i; j &lt; i+chunksize, j &lt; tempStream.size(); ++j)
	{
		tmp.push_back(tempStream[j]);
	}
	datastream.push_back(tmp);
}
</code></pre>
<p>Achtung ! Ungetestet und kein schöner Code, ganz im Gegenteil, ziemlich hässlich und sehr spezialisiert sogar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
Und nicht effizient, das geht besser</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396124</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 24 Apr 2014 13:55:57 GMT</pubDate></item><item><title><![CDATA[Reply to Datastream on Thu, 24 Apr 2014 13:59:49 GMT]]></title><description><![CDATA[<p>Hallo Messinho,</p>
<p>Willkommen im C++-Forum.<br />
Dann meinst Du so was - oder:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;bitset&gt; // nur für Demo-Zwecke (s.write)

void write( unsigned char byte )
{
    std::cout &lt;&lt; std::bitset&lt;8&gt;(byte) &lt;&lt; std::endl;
}

int main()
{
    using namespace std;
    int Buffer[] = {3,9,4,5,1,2,3};
    unsigned char datastream=0; // Zeichen im DataStream
    int bitIdx = 0;

    int bit = 1; // starte mit '1'
    for( int l = 0; l &lt; sizeof(Buffer)/sizeof(*Buffer); ++l, bit = 1-bit )
    {
        for( int i=0; i &lt; Buffer[l]; ++i )
        {
            datastream &lt;&lt;= 1;
            datastream |= bit;
            if( ++bitIdx == 8 )   // datastream ist voll
            {
                write( datastream );
                bitIdx = 0;
            }
        }
    }
    if( bitIdx &gt; 0 )
        write( datastream &lt;&lt; (8-bitIdx) ); // restliche verbleibende Bits scheiben
    cout &lt;&lt; endl;
    return 0;
}
</code></pre>
<p>Output:</p>
<pre><code>11100000
00001111
00000100
11100000
</code></pre>
<p>(getestet und mittel schöner Code)</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396125</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396125</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Thu, 24 Apr 2014 13:59:49 GMT</pubDate></item><item><title><![CDATA[Reply to Datastream on Thu, 24 Apr 2014 14:31:36 GMT]]></title><description><![CDATA[<p>Zunächst einmal herzlichen Dank an euch für eure Hilfe. Ich muss jedoch gestehen, dass ich eher ein Anfänger bin und deshalb eure Code-Vorschläge nicht auf Anhieb verstanden habe.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/7393">@Werner</a><br />
Ich verstehe nicht ganz was hier die Eintrittsbedingung ist:</p>
<pre><code>for( int l = 0; l &lt; /*sizeof(Buffer)/sizeof(*Buffer)*/; ++l, bit = 1-bit )
</code></pre>
<p>SOnst sieht dein Vorschlag ganz gut aus und könnte die fast schon ideale Lösung sein. Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396132</guid><dc:creator><![CDATA[Messinho]]></dc:creator><pubDate>Thu, 24 Apr 2014 14:31:36 GMT</pubDate></item><item><title><![CDATA[Reply to Datastream on Thu, 24 Apr 2014 15:47:48 GMT]]></title><description><![CDATA[<p>Messinho schrieb:</p>
<blockquote>
<p>Ich verstehe nicht ganz was hier die Eintrittsbedingung ist:</p>
<pre><code>for( int l = 0; l &lt; /*sizeof(Buffer)/sizeof(*Buffer)*/; ++l, bit = 1-bit )
</code></pre>
</blockquote>
<p>Der Ausdruck 'sizeof(Buffer)' liefert Dir die Größe in Byte, die der Buffer belegt. Da er 7 int-Werte enthält und jeder int-Wert (in einer 32bit-Umgebung) 4 Byte groß ist, sollte das 4*7=28 sein. Was man hier haben will, ist aber die Anzahl der int-Werte, so dass die Lauf-variable 'l' von 0 bis 7-1=6 gehen kann. Also wird die Größe durch die Größe eines int-Werts geteilt. Und ein int-Wert ist hier '*Buffer', was der erste Wert im Buffer ist. sizeof(*Buffer) liefert also 4. Und 28/4 macht eben 7, also die Anzahl.</p>
<p>Warum macht man das?<br />
Ein ganz wichtiger Punkt beim Programmieren im Allgemeinen ist das Vermeiden von Redundanzen. Betrachte dazu die Sequenz:</p>
<pre><code>int Buffer[] = {3,9,4,5,1,2,3};
    size_t Anzahl = sizeof(Buffer)/sizeof(*Buffer);
</code></pre>
<p>Du kannst jetzt ein Element im Buffer hinzu fügen, ohne etwas anderes ändern zu müssen. Auch kannst Du den Typ der Elemente ändern, ohne auf etwas anderes Rücksicht zu nehmen. Also z.B.:</p>
<pre><code>short Buffer[] = {3,9,4,5,1,2,3,9,1,2,2,2,8};
    size_t Anzahl = sizeof(Buffer)/sizeof(*Buffer);
</code></pre>
<p>.. es ist alles noch so wie es sich der Programmierer am Anfang gedacht hat.</p>
<p>Ungünstig wäre z.B.:</p>
<pre><code>const size_t Anzahl = 7;
    int Buffer[Anzahl] = {3,9,4,5,1,2,3};
</code></pre>
<p>Fügst Du ein Element hinzu, so musst Du auch die Anzahl ändern. Vergisst Du eines von beiden, so macht der Code nicht mehr das, was Du denkst. Die 7 ist redundant zu der Anzahl der Elemete.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396153</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Thu, 24 Apr 2014 15:47:48 GMT</pubDate></item><item><title><![CDATA[Reply to Datastream on Fri, 25 Apr 2014 07:24:00 GMT]]></title><description><![CDATA[<p>Vielen Dank für deine Hilfe Werner! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396203</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396203</guid><dc:creator><![CDATA[Messinho]]></dc:creator><pubDate>Fri, 25 Apr 2014 07:24:00 GMT</pubDate></item></channel></rss>