<?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[Speicherfrage]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hab grad ein verständnis problem.</p>
<p>und zwar habe ich zb. ein string = &quot;1111100&quot; und möchte diesen nur mit 1 byte speichern. jetzt hat aber sogar ein char schon 1 byte. wie kann ich dann den string mit 1 byte speichern ?</p>
<p>Grüße,<br />
Klaus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/289491/speicherfrage</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 02:58:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/289491.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Jul 2011 00:40:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Speicherfrage on Wed, 06 Jul 2011 00:40:10 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hab grad ein verständnis problem.</p>
<p>und zwar habe ich zb. ein string = &quot;1111100&quot; und möchte diesen nur mit 1 byte speichern. jetzt hat aber sogar ein char schon 1 byte. wie kann ich dann den string mit 1 byte speichern ?</p>
<p>Grüße,<br />
Klaus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089328</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089328</guid><dc:creator><![CDATA[Klaus12]]></dc:creator><pubDate>Wed, 06 Jul 2011 00:40:10 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherfrage on Wed, 06 Jul 2011 01:01:29 GMT]]></title><description><![CDATA[<p>Wandle ihn in eine Zahl um und schieb sie in eine Variable vom Typ <code>char</code> oder <code>unsigned char</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089330</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089330</guid><dc:creator><![CDATA[Athar]]></dc:creator><pubDate>Wed, 06 Jul 2011 01:01:29 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherfrage on Wed, 06 Jul 2011 01:02:04 GMT]]></title><description><![CDATA[<p>Gar nicht...</p>
<p>Es sei denn du weißt, dass dein String eine maximal 8bit lange Binärzahl repräsentiert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089331</guid><dc:creator><![CDATA[Impossible]]></dc:creator><pubDate>Wed, 06 Jul 2011 01:02:04 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherfrage on Wed, 06 Jul 2011 01:08:50 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">char BinToChar(const char *s)
{
  char c = 0;
  std::size_t len = std::strlen(s);
  for (std::size_t i = 0; i &lt; len; ++i)
  {
    if (s[i] == '1')
      c += 1 &lt;&lt; len - 1 - i;
  }
  return c;
}
</code></pre>
<p>Ist vermutlich das, was du willst. Denn</p>
<blockquote>
<p>wie kann ich dann den string mit 1 byte speichern ?</p>
</blockquote>
<p>ist nicht möglich, wie ja schon erwähnt wurde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089332</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089332</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Wed, 06 Jul 2011 01:08:50 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherfrage on Wed, 06 Jul 2011 01:16:55 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/25760">@cooky451</a><br />
genau das suche ich.</p>
<p>aber ehrlich gesagt versteh ich nicht wirklich wieso man das machen kann.<br />
ich hab ein char, und schreib in diesen meinen string rein.</p>
<p>mit s = &quot;101&quot; ist dann c = 101 ?</p>
<p>wie genau funktioniert denn das shiften ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089333</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089333</guid><dc:creator><![CDATA[Klaus12]]></dc:creator><pubDate>Wed, 06 Jul 2011 01:16:55 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherfrage on Wed, 06 Jul 2011 01:27:35 GMT]]></title><description><![CDATA[<p>hm, der übersetzt das einfach in eine ganz normale zahl oder ?</p>
<p>sprich s = 111 =&gt; b= 7</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089334</guid><dc:creator><![CDATA[Klaus12]]></dc:creator><pubDate>Wed, 06 Jul 2011 01:27:35 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherfrage on Wed, 06 Jul 2011 01:34:51 GMT]]></title><description><![CDATA[<p>Klaus12 schrieb:</p>
<blockquote>
<p>ich hab ein char, und schreib in diesen meinen string rein.</p>
</blockquote>
<p>Nein, du schreibst da eben gerade nicht deinen String rein. Gehen wir mal von char = byte = 8 bit aus. Dann hast du in einem byte acht Schalter, die entweder an oder aus sein können. Du kannst also jede Kombination dieser acht Schalter in einem byte speichern. Den vermeintlich &quot;größeren&quot; String kannst du nur auf ein char konzentrieren, da nur zwei Zeichen vorkommen, die du als &quot;an&quot; bzw. &quot;aus&quot; interpretierst. Das funktioniert auch nur so, es können keine andere Zeichen in dem String sein.<br />
<a href="http://de.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange" rel="nofollow">ASCII</a> solltest du dir mal angucken.</p>
<p>Das shiften funktioniert ganz einfach.<br />
x &lt;&lt; a;<br />
Verschiebt alle Bits von x um a Stellen. Wenn man also x = 5 und a = 2 setzt:<br />
(5 &lt;&lt; 2) == 20<br />
bzw.<br />
(101 &lt;&lt; 2) == (10100)</p>
<p>Mit der 1 als Basis macht man es sich einfach, man setzt das erste Bit und verschiebt es um so viele Stellen wie man gerade möchte.<br />
<a href="http://de.wikibooks.org/wiki/C-Programmierung:_Ausdr%C3%BCcke_und_Operatoren#Bitmanipulation" rel="nofollow">http://de.wikibooks.org/wiki/C-Programmierung:_Ausdrücke_und_Operatoren#Bitmanipulation</a></p>
<p>Edit:<br />
Und da der String mit dem höchstwertigen Bit anfängt (bei 5 = 101 wäre 100 = 4 und 001 = 1) muss man die erste 1 halt um (Stringlänge) - 1 verschieben, das zweite um (Stringlänge) - 2 etc.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2089335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089335</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Wed, 06 Jul 2011 01:34:51 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherfrage on Wed, 06 Jul 2011 01:38:36 GMT]]></title><description><![CDATA[<p>ahh, ich glaub jetzt hab ichs auch verstanden!</p>
<p>danke schön <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/2089336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2089336</guid><dc:creator><![CDATA[Klaus12]]></dc:creator><pubDate>Wed, 06 Jul 2011 01:38:36 GMT</pubDate></item></channel></rss>