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'])
 def test_int_to_fixed_width_3(self):
     n = [
         (0, ['00000000', '00000000', '00000000']),
         (1, ['00000000', '00000000', '00000001']),
         (255, ['00000000', '00000000', '11111111']),
         (32768, ['00000000', '10000000', '00000000']),
         (32769, ['00000000', '10000000', '00000001']),
     ]
     for k, v in n:
         self.assertEqual(by.to_bit(by.int_to(k, 3)), v)
 def test_to_bit(self):
     n= [
         ([0], ['00000000']),
         ([1], ['00000001']),
         ([7], ['00000111']),
         ([8], ['00001000']),
         ([255], ['11111111']),
         ([128, 0], ['10000000', '00000000']),
         ([128, 1], ['10000000', '00000001']),
     ]
     for k, v in n:
         self.assertEqual(by.to_bit(bytearray(k)), v)
 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)
 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)