<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.ta.in.th/index.php?action=history&amp;feed=atom&amp;title=Bit_Count</id>
	<title>Bit Count - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.ta.in.th/index.php?action=history&amp;feed=atom&amp;title=Bit_Count"/>
	<link rel="alternate" type="text/html" href="https://wiki.ta.in.th/index.php?title=Bit_Count&amp;action=history"/>
	<updated>2026-05-02T16:46:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0-alpha</generator>
	<entry>
		<id>https://wiki.ta.in.th/index.php?title=Bit_Count&amp;diff=101&amp;oldid=prev</id>
		<title>Tata: Created page with &quot;== อันนี้เป็นแบบ version ทำมือ == เห็นฟังก์ชั่นนี้มันเจ๋งดี ใช้นับจำน...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.ta.in.th/index.php?title=Bit_Count&amp;diff=101&amp;oldid=prev"/>
		<updated>2019-03-07T17:17:15Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== อันนี้เป็นแบบ version ทำมือ == เห็นฟังก์ชั่นนี้มันเจ๋งดี ใช้นับจำน...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== อันนี้เป็นแบบ version ทำมือ ==&lt;br /&gt;
เห็นฟังก์ชั่นนี้มันเจ๋งดี ใช้นับจำนวน bit 1 ในเลขฐาน 2  ใช้ constant time&lt;br /&gt;
อันนี้มันมีบอกหลักการกับพิสูจน์ในเว็บอ่ะ ถ้าสนใจก็ลองดูต่อในเว็บละกัน&lt;br /&gt;
&lt;br /&gt;
 int BitCount(unsigned int u)&lt;br /&gt;
 {&lt;br /&gt;
         unsigned int uCount;&lt;br /&gt;
         uCount = u - ((u &amp;gt;&amp;gt; 1) &amp;amp; 033333333333) - ((u &amp;gt;&amp;gt; 2) &amp;amp; 011111111111);&lt;br /&gt;
         return  ((uCount + (uCount &amp;gt;&amp;gt; 3)) &amp;amp; 030707070707) % 63;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
มีอีกอันนึง&lt;br /&gt;
&lt;br /&gt;
 int BitCount (unsigned int u)&lt;br /&gt;
 {&lt;br /&gt;
          unsigned int uCount=0 ;&lt;br /&gt;
          for(; u; u&amp;amp;=(u-1))&lt;br /&gt;
             uCount++;&lt;br /&gt;
          return uCount ;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Credit : http://tekpool.wordpress.com/category/bit-count/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== เพิ่งเจอ...มันมีฟังก์ชั่น สำเร็จรูป ==&lt;br /&gt;
=== Function __builtin_clz ===&lt;br /&gt;
ฟังก์ชันสำหรับนับจำนวนบิต 0 ที่อยู่ทางซ้ายก่อนจะเจอบิต 1&lt;br /&gt;
 int __builtin_clz (unsigned int x)&lt;br /&gt;
เช่น&lt;br /&gt;
 __builtin_clz(16);&lt;br /&gt;
ซึ่ง 16 ใน unsigned int จะเป็น&lt;br /&gt;
 '''00000000 00000000 00000000 000'''10000&lt;br /&gt;
__builtin_clz(16); จึงมีค่า (return ออกมา)  เป็น 27&lt;br /&gt;
&lt;br /&gt;
=== Function __builtin_ctz ===&lt;br /&gt;
ฟังก์ชันสำหรับนับจำนวนบิต 0 ที่อยู่ทางขวาก่อนจะเจอบิต 1&lt;br /&gt;
 __builtin_ctz(16);&lt;br /&gt;
ซึ่ง 16 ใน unsigned int จะเป็น&lt;br /&gt;
 00000000 00000000 00000000 0001'''0000'''&lt;br /&gt;
__builtin_ctz(16); จึงมีค่า (return ออกมา)  เป็น 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Function __builtin_popcount ===&lt;br /&gt;
ฟังก์ชันสำหรับนับจำนวนบิต 1 ทั้งหมด&lt;br /&gt;
 __builtin_popcount(16);&lt;br /&gt;
ซึ่ง 16 ใน unsigned int จะเป็น&lt;br /&gt;
 00000000 00000000 00000000 000'''1'''0000&lt;br /&gt;
__builtin_popcount; จึงมีค่า (return ออกมา)  เป็น 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Credit: http://www.go4expert.com/articles/builtin-gcc-functions-builtinclz-t29238/&lt;/div&gt;</summary>
		<author><name>Tata</name></author>
		
	</entry>
</feed>