<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" >

  <channel>
    <title><![CDATA[Комментарии / Профиль timtimon]]></title>
    <link>https://habr.com/ru/users/timtimon/comments/</link>
    <description><![CDATA[Хабр: комментарии пользователя timtimon]]></description>
    <language>ru</language>
    <managingEditor>editor@habr.com</managingEditor>
    <generator>habr.com</generator>
    <pubDate>Fri, 01 May 2026 08:38:30 GMT</pubDate>
    
    
      <image>
        <link>https://habr.com/ru/</link>
        <url>https://habrastorage.org/webt/ym/el/wk/ymelwk3zy1gawz4nkejl_-ammtc.png</url>
        <title>Хабр</title>
      </image>
    

    
      

      
        
  
    <item>
      <title>21.04.2023 11:06:29 </title>
      <guid isPermaLink="true">https://habr.com/ru/articles/522788/#comment_25472242</guid>
      <link>https://habr.com/ru/articles/522788/#comment_25472242</link>
      <description><![CDATA[<p>Тоже решал такую задачку, но пошёл по другому пути.<br>
Суть метода: преобразовать целое число в double и уже из двоичного представления double извлечь степень двойки.</p><br>
<pre><code class="plaintext">#include &lt;type_traits&gt;

/// Integral part of log2(n), n - integral (interpreted as unsigned)
template &lt;class _Int, class = std::enable_if_t&lt;std::is_integral&lt;_Int&gt;::value&gt;&gt;
  constexpr int ilog2(_Int n) noexcept
    {
      struct Bits {
        constexpr auto bias() const noexcept { return 1023; }
        uint64_t m: 52;
        uint64_t e: 11;
        uint64_t s:  1;
      };

      union FRep {
        constexpr FRep(double f) noexcept : v(f) {}
        constexpr int ilog2() const noexcept
          { return b.e &gt;= b.bias() ? int(b.e) - b.bias() : -1; }
        double v;
        Bits b;
      };

      return FRep(double(uint64_t(n))).ilog2();
    }

/// Most significant bit // Старший значащий бит
/// @return 2^i or 0, i = index of the MSB;
template &lt;class _Int, class = std::enable_if_t&lt;std::is_integral&lt;_Int&gt;::value&gt;&gt;
  constexpr auto msb(_Int n) noexcept
    {
      using Unsigned = std::make_unsigned_t&lt;_Int&gt;;
      return !n ? 0 : n == _Int(-1) ? Unsigned(-1) ^ (Unsigned(-1) &gt;&gt; 1)
                                    : Unsigned(1) &lt;&lt; ilog2(n);
    }</code></pre>]]></description>
      <pubDate>Fri, 21 Apr 2023 11:06:29 GMT</pubDate>
      <dc:creator><![CDATA[]]></dc:creator>
    </item>
  

      

      

    
  </channel>
</rss>
