<?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[anzahl benötigter bits]]></title><description><![CDATA[<p>hi, hab ne ziemlich peinliche frage.</p>
<p>ich möchte berechnen, wie viele bits ich brauche um eine menge an elementen einzigartig darzustellen. z.b. 8 elemente -&gt; 3 bits. entweder stehe gerade auf nem schlauch oder ich bin echt so dumm, ka...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/319557/anzahl-benötigter-bits</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Jul 2026 05:08:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319557.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Aug 2013 05:43:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 05:43:47 GMT]]></title><description><![CDATA[<p>hi, hab ne ziemlich peinliche frage.</p>
<p>ich möchte berechnen, wie viele bits ich brauche um eine menge an elementen einzigartig darzustellen. z.b. 8 elemente -&gt; 3 bits. entweder stehe gerade auf nem schlauch oder ich bin echt so dumm, ka...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2347972</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2347972</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Fri, 23 Aug 2013 05:43:47 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 05:55:25 GMT]]></title><description><![CDATA[<p>Logarithmus....?<br />
<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>l</mi><mi>o</mi><msub><mi>g</mi><mn>2</mn></msub><mo>(</mo><mn>8</mn><mo>)</mo><mtext> </mtext><mo>=</mo><mtext> </mtext><mn>3</mn></mrow><annotation encoding="application/x-tex">log_2(8) ~=~ 3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">o</span><span class="mord"><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:-0.03588em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle cramped"><span class="mord mathrm">2</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span><span class="mopen">(</span><span class="mord mathrm">8</span><span class="mclose">)</span><span class="mord mspace"> </span><span class="mrel">=</span><span class="mord mspace"> </span><span class="mord mathrm">3</span></span></span></span></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2347973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2347973</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Fri, 23 Aug 2013 05:55:25 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 05:55:57 GMT]]></title><description><![CDATA[<p>Das geht mit dem Logarithmus zur Basis 2. Und dann aufrunden.<br />
Wenn du den nicht hast musst du halt umrechnen:<br />
z.B. ceil(log(anz)/log(2))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2347974</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2347974</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Fri, 23 Aug 2013 05:55:57 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 05:56:16 GMT]]></title><description><![CDATA[<p>Logarthmus-Funktion. In Deinem Beispiel:<br />
log(8) / log(2) = 3<br />
Das Ergebnis muss natürlich aufgerundet werden, weil Du für 7 Elemente ja auch 3 bit brauchst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2347975</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2347975</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Fri, 23 Aug 2013 05:56:16 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 05:58:36 GMT]]></title><description><![CDATA[<p>achja log n / log 2. ich war grad bissl verwirrt weil es ja keinen log mit basis 2 von c++ aus direkt gibt. danke viel mals an alle</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2347976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2347976</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Fri, 23 Aug 2013 05:58:36 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 09:24:14 GMT]]></title><description><![CDATA[<p>So etwas kann man auch wunderbar tabellieren, dann spart man sich den teuren Logarithmus für solch eine triviale Berechnung. Da man weiterhin wohl nur an der Anzahl nötiger chars interessiert ist, wird die Tabelle sogar um einen Faktor 8 kleiner, als man naiv annehmen würde:</p>
<pre><code>unsigned get_number_of_chars(size_t cardinality)
{
  for (unsigned i = 0; i &lt; sizeof(cardinality); ++i)
    if (cardinality &lt; 1 &lt;&lt; i * CHAR_BIT) return i;
  return sizeof(cardinality);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2348034</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348034</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 23 Aug 2013 09:24:14 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 10:10:09 GMT]]></title><description><![CDATA[<p>doktor banane schrieb:</p>
<blockquote>
<p>ich war grad bissl verwirrt weil es ja keinen log mit basis 2 von c++ aus direkt gibt.</p>
</blockquote>
<p>Ja, das versteh ich auch nicht ganz.</p>
<p>Man kann sich aber mit</p>
<pre><code class="language-cpp">sizeof(unsigned) - __builtin_clz(i)
</code></pre>
<p>behelfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348049</guid><dc:creator><![CDATA[clzlclzl]]></dc:creator><pubDate>Fri, 23 Aug 2013 10:10:09 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 11:02:27 GMT]]></title><description><![CDATA[<p>Zusatzfrage: Ist eine einfache, platformunabhängige Implementierung möglich, die die benötigte Bytezahl einer Compilezeitkonstanten zur Compilezeite berechnet? Ich denke das wäre für einige statische Überprüfungen durchaus hilfreich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348075</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Fri, 23 Aug 2013 11:02:27 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 11:06:26 GMT]]></title><description><![CDATA[<p>Da könnte man doch sicher was mit TMP machen, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348080</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348080</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 23 Aug 2013 11:06:26 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 11:07:49 GMT]]></title><description><![CDATA[<p>Man kann das sicherlich, ich aber leider nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348082</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Fri, 23 Aug 2013 11:07:49 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 11:13:09 GMT]]></title><description><![CDATA[<p>Damit ergeben sich doch sicherlich sehr viele tolle Möglichkeite für Templates wie: &quot;Wähle als Typ für die Variable den kleinsten unsigned Integertyp, in den die Zahl noch gerade rein passt&quot;. Mir fällt aber gerade auf, dass man das viel leichter mit numeric_limits lösen kann, falls ich mich nicht irre.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348083</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Fri, 23 Aug 2013 11:13:09 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 11:23:04 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>Ich denke das wäre für einige statische Überprüfungen durchaus hilfreich.</p>
</blockquote>
<p>Braucht kein Mensch.</p>
<blockquote>
<p>Wähle als Typ für die Variable den kleinsten unsigned Integertyp, in den die Zahl noch gerade rein passt</p>
</blockquote>
<pre><code class="language-cpp">auto i = 999999999999;
</code></pre>
<blockquote>
<p>Mir fällt aber gerade auf, dass man das viel leichter mit numeric_limits lösen kann, falls ich mich nicht irre.</p>
</blockquote>
<p>Hmm... Du bist ein ganz Schlauer!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348086</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348086</guid><dc:creator><![CDATA[g3il3rCXXfr33k]]></dc:creator><pubDate>Fri, 23 Aug 2013 11:23:04 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 11:35:44 GMT]]></title><description><![CDATA[<p>g3il3rCXXfr33k schrieb:</p>
<blockquote>
<blockquote>
<p>Wähle als Typ für die Variable den kleinsten unsigned Integertyp, in den die Zahl noch gerade rein passt</p>
</blockquote>
<pre><code class="language-cpp">auto i = 999999999999;
</code></pre>
</blockquote>
<p>Das erzeugt aber eine Initialisierung zur Laufzeit die man eventuell nicht haben möchte oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348093</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Fri, 23 Aug 2013 11:35:44 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 11:37:19 GMT]]></title><description><![CDATA[<p>doktor banane schrieb:</p>
<blockquote>
<p>achja log n / log 2. ich war grad bissl verwirrt weil es ja keinen log mit basis 2 von c++ aus direkt gibt. danke viel mals an alle</p>
</blockquote>
<p>siehe auch <a href="http://en.cppreference.com/w/cpp/numeric/math/log2" rel="nofollow">http://en.cppreference.com/w/cpp/numeric/math/log2</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348094</guid><dc:creator><![CDATA[dd++ 0]]></dc:creator><pubDate>Fri, 23 Aug 2013 11:37:19 GMT</pubDate></item><item><title><![CDATA[Reply to anzahl benötigter bits on Fri, 23 Aug 2013 12:51:57 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>g3il3rCXXfr33k schrieb:</p>
<blockquote>
<blockquote>
<p>Wähle als Typ für die Variable den kleinsten unsigned Integertyp, in den die Zahl noch gerade rein passt</p>
</blockquote>
<pre><code class="language-cpp">auto i = 999999999999;
</code></pre>
</blockquote>
<p>Das erzeugt aber eine Initialisierung zur Laufzeit die man eventuell nicht haben möchte oder?</p>
</blockquote>
<p>Dann eben:</p>
<pre><code>decltype(999999999999) i;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2348117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348117</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Fri, 23 Aug 2013 12:51:57 GMT</pubDate></item></channel></rss>