コード例 #1
0
 def test_bit_set(self):
     # 0010 0011 1100 0010
     ba0 = bytearray(2)
     bi.bit_set(ba0, 2)
     bi.bit_set(ba0, 6, "1111")
     bi.bit_set(ba0, 14)
     self.assertEqual(by.to_bit(ba0), ['00100011', '11000010'])
コード例 #2
0
 def test_bit_set_extend(self):
     n = [
         ( 0, ['10000000']),
         ( 1, ['01000000']),
         ( 2, ['00100000']),
         ( 3, ['00010000']),
         ( 4, ['00001000']),
         ( 5, ['00000100']),
         ( 6, ['00000010']),
         ( 7, ['00000001']),
         ( 8, ['00000000', '10000000']),
         ( 9, ['00000000', '01000000']),
         (10, ['00000000', '00100000']),
         (11, ['00000000', '00010000']),
         (12, ['00000000', '00001000']),
         (13, ['00000000', '00000100']),
         (14, ['00000000', '00000010']),
         (15, ['00000000', '00000001']),
         (16, ['00000000', '00000000', '10000000']),
     ]
     for k, v in n:
         ba0 = bytearray(1)
         self.assertEqual(by.to_bit(bi.bit_set(ba0, k, extend=True)), v)
コード例 #3
0
 def test_bit_set_110(self):
     n = [
         ( 0, ['11000000', '00000000']),
         ( 1, ['01100000', '00000000']),
         ( 2, ['00110000', '00000000']),
         ( 3, ['00011000', '00000000']),
         ( 4, ['00001100', '00000000']),
         ( 5, ['00000110', '00000000']),
         ( 6, ['00000011', '00000000']),
         ( 7, ['00000001', '10000000']),
         ( 8, ['00000000', '11000000']),
         ( 9, ['00000000', '01100000']),
         (10, ['00000000', '00110000']),
         (11, ['00000000', '00011000']),
         (12, ['00000000', '00001100']),
         (13, ['00000000', '00000110']),
         (14, ['00000000', '00000011']),
         (15, ['00000000', '00000001']),
         (16, ['00000000', '00000000']),
     ]
     for k, v in n:
         ba0 = bytearray(2)
         self.assertEqual(by.to_bit(bi.bit_set(ba0, k, "110")), v)