예제 #1
0
    def test6(self):
        bv = BitVector(256, val_int=0)
        for numbits in xrange(256,0,-1):
            other = BitVector(numbits, 1<<(numbits-1))
            bv.update_from(other)
            self.assert_( bv.is_same_when_extended( other ))

        other1 = BitVector(8,val_int=0xff)
        for start in xrange(0,256-8):
            bv = BitVector( 256, val_int=0 )
            bv.update_from(other1, self_max = start+7, self_min = start)
            expd = 0xff << start
            bvd = bv.get_bin_data()
            self.assert_(bvd == expd, "\nexpd=0x%x\nbv  =0x%x" % (expd, bvd))

            
        c = 0x12345678abcd112212345678abcd1122
        c2 = 0x556611ff
        other2 = BitVector(32,c2)
        for start in xrange(0,256-32):
            bv = BitVector( 256, c )
            bv.update_from(other2, self_max = start+31, self_min = start)
            expd = c & ~(0xffffffff << start) | ( c2 << start)
            bvd = bv.get_bin_data()
            self.assert_(bvd == expd, "\nstart=%d\nexpd=0x%x\nbv  =0x%x" % (start, expd, bvd))
예제 #2
0
 def test4(self):
     bv = BitVector(32, 0x12345678)
     for bitlen in xrange(1,32):
         mask = ( 1 << bitlen ) - 1
         for start in xrange(0,(32-bitlen+1)):
             end = start + bitlen - 1
             exp_d = ( 0x12345678 >> start ) & mask
             bv_d = bv.get_bin_data( self_max=end, self_min=start)
             # print "bv.get_bin_data(%d,%d) == 0x%x.   Exp=0x%x" % (end, start, bv_d, exp_d)
             self.assert_(bv_d == exp_d," exp:0x%x\nsaw:0x%x   [%d,%d]" % (exp_d, bv_d, end,start))