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:
“I shall christen this style the Mandarin, since it is beloved by literary pundits, by those who would make the written word as unlike as possible to the spoken one. It is the style of all those writers whose tendency is to make their language convey more than they mean or more than they feel, it is the style of most artists and all humbugs.”
—Cyril Connolly (19031974)
“The interest in Wisdom is fading. Soon there will not be enough left to support the aphorism, even though it tries to amuse by half-mocking the Wisdom it propounds.”
—Mason Cooley (b. 1927)