<?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[Präfixlänge von IPv4 Adressmasken berechnen.]]></title><description><![CDATA[<p>Ich brauche von einer Adressmaske die Präfixlänge also auf gut deutsch: Die Anzahl an zusammenhängenden Einsen am Anfang eines Integers berechnen. Wie macht man das am geschicktesten?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/325521/präfixlänge-von-ipv4-adressmasken-berechnen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 08:19:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325521.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 May 2014 12:35:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Präfixlänge von IPv4 Adressmasken berechnen. on Tue, 06 May 2014 12:35:34 GMT]]></title><description><![CDATA[<p>Ich brauche von einer Adressmaske die Präfixlänge also auf gut deutsch: Die Anzahl an zusammenhängenden Einsen am Anfang eines Integers berechnen. Wie macht man das am geschicktesten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397649</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Tue, 06 May 2014 12:35:34 GMT</pubDate></item><item><title><![CDATA[Reply to Präfixlänge von IPv4 Adressmasken berechnen. on Tue, 06 May 2014 12:41:34 GMT]]></title><description><![CDATA[<p>Schon auf <a href="http://graphics.stanford.edu/~seander/bithacks.html" rel="nofollow">Bit Twiddling Hacks</a> nachgeschaut? (Zuerst negieren könnte helfen.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397651</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 06 May 2014 12:41:34 GMT</pubDate></item><item><title><![CDATA[Reply to Präfixlänge von IPv4 Adressmasken berechnen. on Tue, 06 May 2014 12:51:51 GMT]]></title><description><![CDATA[<p>Im Prinzip wäre das ja 32 - &quot;Count the consecutive zero bits (trailing)&quot;. Finde ich jetzt nicht so schön aber dürfte es tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397658</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397658</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Tue, 06 May 2014 12:51:51 GMT</pubDate></item><item><title><![CDATA[Reply to Präfixlänge von IPv4 Adressmasken berechnen. on Tue, 06 May 2014 13:09:31 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>Im Prinzip wäre das ja 32 - &quot;Count the consecutive zero bits (trailing)&quot;. Finde ich jetzt nicht so schön aber dürfte es tun.</p>
</blockquote>
<p>Hä? Bau Dir eine Funktion count_trailing_zeros und tausch ihre Implementierung per #ifdef gegebenenfalls gegen compilerintrinsics oder inline asm aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397664</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 06 May 2014 13:09:31 GMT</pubDate></item><item><title><![CDATA[Reply to Präfixlänge von IPv4 Adressmasken berechnen. on Tue, 06 May 2014 13:18:50 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>TNA schrieb:</p>
<blockquote>
<p>Im Prinzip wäre das ja 32 - &quot;Count the consecutive zero bits (trailing)&quot;. Finde ich jetzt nicht so schön aber dürfte es tun.</p>
</blockquote>
<p>Hä? Bau Dir eine Funktion count_trailing_zeros und tausch ihre Implementierung per #ifdef gegebenenfalls gegen compilerintrinsics oder inline asm aus.</p>
</blockquote>
<p>Ich brauche ja eigentlich die Anzahl der Einsen und nicht die der Nullen und müsste das daher umrechnen. Mit deiner Antwort kann ich aber leider auch wenig anfangen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397668</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397668</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Tue, 06 May 2014 13:18:50 GMT</pubDate></item><item><title><![CDATA[Reply to Präfixlänge von IPv4 Adressmasken berechnen. on Tue, 06 May 2014 13:27:32 GMT]]></title><description><![CDATA[<p>Du kannst auch direkt die gesetzten Bits zählen?!<br />
Nexus' Link hat einen ganzen Sack voll von Algorithmen zum Thema <em>&quot;Counting bits set&quot;</em>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397672</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Tue, 06 May 2014 13:27:32 GMT</pubDate></item><item><title><![CDATA[Reply to Präfixlänge von IPv4 Adressmasken berechnen. on Tue, 06 May 2014 13:30:32 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>Mit deiner Antwort kann ich aber leider auch wenig anfangen.</p>
</blockquote>
<p>Es gibt auf vielen Prozessoren einen eigenen Prozessorbefehl dafür.<br />
<a href="http://en.wikipedia.org/wiki/Find_first_set" rel="nofollow">http://en.wikipedia.org/wiki/Find_first_set</a><br />
<a href="http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html" rel="nofollow">http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html</a> __builtin_ctz</p>
<pre><code>#if defined MSVC
int count_trailing_zeros(unsigned int x){
   __asm bsf x;
}
#elif defined GCC
int count_trailing_zeros(unsigned int x){
   return __builtin_ctz(x);
}
#else
int count_trailing_zeros(unsigned int x){
   //kopiert aus &quot;bit twiddleing hacks&quot;
}
#endif
</code></pre>
<p>Und dann ist</p>
<pre><code>int getPrefixLength(int addr){
   return count_trailing_zeros(~addr);
}
</code></pre>
<p>recht schmerzfrei.</p>
<p>(Code nur zu Demonstrationszwecken, habe ihn nicht im Mindesten geprüft.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397675</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 06 May 2014 13:30:32 GMT</pubDate></item></channel></rss>