コード例 #1
0
        public void Test_LowestOneBit_Int64()
        {
            assertEquals(0x10L, BitOperation.LowestOneBit(0xF0L));

            assertEquals(0x10L, BitOperation.LowestOneBit(0x90L));
            assertEquals(0x10L, BitOperation.LowestOneBit(0xD0L));

            assertEquals(0x10L, BitOperation.LowestOneBit(0x123490L));
            assertEquals(0x10L, BitOperation.LowestOneBit(0x1234D0L));

            assertEquals(0x100000L, BitOperation.LowestOneBit(0x900000L));
            assertEquals(0x100000L, BitOperation.LowestOneBit(0xD00000L));

            assertEquals(0x40L, BitOperation.LowestOneBit(0x40L));
            assertEquals(0x40L, BitOperation.LowestOneBit(0xC0L));

            assertEquals(0x4000L, BitOperation.LowestOneBit(0x4000L));
            assertEquals(0x4000L, BitOperation.LowestOneBit(0xC000L));

            assertEquals(0x4000L, BitOperation.LowestOneBit(0x99994000L));
            assertEquals(0x4000L, BitOperation.LowestOneBit(0x9999C000L));

            assertEquals(0L, BitOperation.LowestOneBit(0L));
            assertEquals(1L, BitOperation.LowestOneBit(1L));
            assertEquals(1L, BitOperation.LowestOneBit(-1L));
        }
コード例 #2
0
        public void Test_LowestOneBit_Int32()
        {
            assertEquals(0x10, BitOperation.LowestOneBit(0xF0));

            assertEquals(0x10, BitOperation.LowestOneBit(0x90));
            assertEquals(0x10, BitOperation.LowestOneBit(0xD0));

            assertEquals(0x10, BitOperation.LowestOneBit(0x123490));
            assertEquals(0x10, BitOperation.LowestOneBit(0x1234D0));

            assertEquals(0x100000, BitOperation.LowestOneBit(0x900000));
            assertEquals(0x100000, BitOperation.LowestOneBit(0xD00000));

            assertEquals(0x40, BitOperation.LowestOneBit(0x40));
            assertEquals(0x40, BitOperation.LowestOneBit(0xC0));

            assertEquals(0x4000, BitOperation.LowestOneBit(0x4000));
            assertEquals(0x4000, BitOperation.LowestOneBit(0xC000));

            assertEquals(0x4000, BitOperation.LowestOneBit(unchecked ((int)0x99994000)));
            assertEquals(0x4000, BitOperation.LowestOneBit(unchecked ((int)0x9999C000)));

            assertEquals(0, BitOperation.LowestOneBit(0));
            assertEquals(1, BitOperation.LowestOneBit(1));
            assertEquals(1, BitOperation.LowestOneBit(-1));
        }