System.Xml.Bits.Count C# (CSharp) Méthode

Count() public static méthode

Returns the number of 1 bits in an unsigned integer. Counts bits by divide-and-conquer method, first computing 16 2-bit counts, then 8 4-bit counts, then 4 8-bit counts, then 2 16-bit counts, and finally 1 32-bit count.
public static Count ( uint num ) : int
num uint
Résultat int
        public static int Count(uint num) {
            num = (num & MASK_0101010101010101) + ((num >> 1) & MASK_0101010101010101);
            num = (num & MASK_0011001100110011) + ((num >> 2) & MASK_0011001100110011);
            num = (num & MASK_0000111100001111) + ((num >> 4) & MASK_0000111100001111);
            num = (num & MASK_0000000011111111) + ((num >> 8) & MASK_0000000011111111);
            num = (num & MASK_1111111111111111) + (num >> 16);

            return (int) num;
        }