Language Support
Some C compilers provide intrinsics that provide bit counting facilities. For example, GCC (since version 3.4 in April 2004) includes a builtin function __builtin_popcount that will use a processor instruction if available or an efficient library implementation otherwise. LLVM-GCC has included this function since version 1.5 in June, 2005.
In C++ STL, the bit-array data structure bitset has a count method that counts the number of bits that are set.
In Java, the growable bit-array data structure BitSet has a BitSet.cardinality method that counts the number of bits that are set. In addition, there are Integer.bitCount(int) and Long.bitCount(long) functions to count bits in primitive 32-bit and 64-bit integers, respectively. Also, the BigInteger arbitrary-precision integer class also has a BigInteger.bitCount method that counts bits.
In Common Lisp, the function logcount, given a non-negative integer, returns the number of 1 bits. (For negative integers it returns the number of 0 bits in 2's complement notation.) In either case the integer can be a BIGNUM.
Read more about this topic: Hamming Weight
Famous quotes containing the words language and/or support:
“A mind enclosed in language is in prison.”
—Simone Weil (19091943)
“There is a period near the beginning of every mans life when he has little to cling to except his unmanageable dream, little to support him except good health, and nowhere to go but all over the place.”
—E.B. (Elwyn Brooks)