Example #1
0
 //This uses fewer arithmetic operations than any other known  
 //implementation on machines with fast multiplication.
 //It uses 12 arithmetic operations, one of which is a multiply.
 static int popcount_3(uint64 x)
 {
     x -= (x >> 1) & m1;             //put count of each 2 bits into those 2 bits
     x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits 
     x = (x + (x >> 4)) & m4;        //put count of each 8 bits into those 8 bits 
     return (int) ((x * h01) >> 56);  //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ... 
 }
Example #2
0
        // Overrides the ConvertFrom method of TypeConverter.
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                uint64 result = ulong.Parse((string)value);
                return(result);
            }

            return(base.ConvertFrom(context, culture, value));
        }
Example #3
0
 //This uses fewer arithmetic operations than any other known  
 //implementation on machines with slow multiplication.
 //It uses 17 arithmetic operations.
 static int popcount_2(uint64 x)
 {
     x -= (x >> 1) & m1;             //put count of each 2 bits into those 2 bits
     x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits 
     x = (x + (x >> 4)) & m4;        //put count of each 8 bits into those 8 bits 
     x += x >> 8;  //put count of each 16 bits into their lowest 8 bits
     x += x >> 16;  //put count of each 32 bits into their lowest 8 bits
     x += x >> 32;  //put count of each 64 bits into their lowest 8 bits
     return (int) (x & 0x7f);
 }
Example #4
0
        const uint64 h01 = 0x0101010101010101; //the sum of 256 to the power of 0,1,2,3...


        public static int ones(uint64 x)
        {
            x = (x & m1) + ((x >> 1) & m1); //put count of each  2 bits into those  2 bits 
            x = (x & m2) + ((x >> 2) & m2); //put count of each  4 bits into those  4 bits 
            x = (x & m4) + ((x >> 4) & m4); //put count of each  8 bits into those  8 bits 
            x = (x & m8) + ((x >> 8) & m8); //put count of each 16 bits into those 16 bits 
            x = (x & m16) + ((x >> 16) & m16); //put count of each 32 bits into those 32 bits 
            x = (x & m32) + ((x >> 32) & m32); //put count of each 64 bits into those 64 bits 
            return (int)x;
        }
Example #5
0
        private Color ParseColor(string hexColor)
        {
            if (hexColor.Length != 8 || hexColor.Length != 8)
            {
                throw new StyleParseException("Color must be a valid hexedecimal value with 6 or 8 digits");
            }

            uint64 colorValue = Convert.ToUInt64(hexColor, 16);
            float  r;
            float  g;
            float  b;
            float  a;

            return(new Color((float)r / 255f, (float)g / 255f, (float)b / 255f, (float)a / 255f));
        }