Esempio n. 1
0
        public void Bits_BitCountTest2()
        {
            {
                const ulong kBitCountValue = 0xAAAAAAAAAAAAAAAA;
                int         i32;
                int         expected_bit_count;

                expected_bit_count = Bits.kByteBitCount / 2;    i32 = Bits.BitCount(unchecked ((byte)kBitCountValue));
                Assert.AreEqual(expected_bit_count, i32);

                expected_bit_count = Bits.kInt16BitCount / 2;   i32 = Bits.BitCount(unchecked ((ushort)kBitCountValue));
                Assert.AreEqual(expected_bit_count, i32);

                expected_bit_count = Bits.kInt32BitCount / 2;   i32 = Bits.BitCount(unchecked ((uint)kBitCountValue));
                Assert.AreEqual(expected_bit_count, i32);

                expected_bit_count = Bits.kInt64BitCount / 2;   i32 = Bits.BitCount(kBitCountValue);
                Assert.AreEqual(expected_bit_count, i32);
            }

            {
                uint  u32;
                ulong u64;

                u32 = Bits.BitCountToMask32(Bits.kInt32BitCount);
                Assert.AreEqual(u32, uint.MaxValue);

                u32 = Bits.BitCountToMask32(Bits.kInt32BitCount - 1);
                Assert.AreEqual(u32, uint.MaxValue >> 1);

                u64 = Bits.BitCountToMask64(Bits.kInt64BitCount);
                Assert.AreEqual(u64, ulong.MaxValue);

                u64 = Bits.BitCountToMask64(Bits.kInt64BitCount - 1);
                Assert.AreEqual(u64, ulong.MaxValue >> 1);
            }
        }