<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>kaiseh</author_name>
  <author_url>https://blog.hatena.ne.jp/kaiseh/</author_url>
  <blog_title>kaisehのブログ</blog_title>
  <blog_url>https://kaiseh.hatenadiary.org/</blog_url>
  <categories>
    <anon>Java</anon>
  </categories>
  <description>訂正: 整数中に立っているビット数ではなく、立っているビットの最左位置を求める方法でした。 java.util.BitSetのソース中で、整数中に立っているビット数を数えるメソッドが面白かったので載せてみます。二分探索をベタ書きしていて、最大6回の比較でビット数が求まります。この方法が最速なのかな。 private static int bitLen(int w) { return (w &lt; 1&lt;&lt;15 ? (w &lt; 1&lt;&lt;7 ? (w &lt; 1&lt;&lt;3 ? (w &lt; 1&lt;&lt;1 ? (w &lt; 1&lt;&lt;0 ? (w&lt;0 ? 32 : 0) : 1) : (w &lt; 1&lt;&lt;2 ? 2 : 3)) : (w…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fkaiseh.hatenadiary.org%2Fentry%2F20081114%2F1226665036&quot; title=&quot; 整数の中で立っているビット数を求める方法 - kaisehのブログ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2008-11-14 21:17:16</published>
  <title> 整数の中で立っているビット数を求める方法</title>
  <type>rich</type>
  <url>https://kaiseh.hatenadiary.org/entry/20081114/1226665036</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
