code: def put_bits( self, value, count ):
          
          for _ in range( count ):
  
              # bits are retrieved from the source LSB first
              bit = (value & 1)
              value >>= 1
  
              # however, bits are put into the result based on the rule
              if self.bits_reverse:
                  if self.insert_at_msb:
                      self.current_bits |= (bit << (self.bits_remaining-1))
                  else:
                      self.current_bits <<= 1
                      self.current_bits |= bit
              else:
                  if self.insert_at_msb:
                      self.current_bits >>= 1
                      self.current_bits |= (bit << 7)
                  else:
                      self.current_bits |= (bit << (8-self.bits_remaining))
  
              self.bits_remaining -= 1
              if self.bits_remaining <= 0:
                  self.output.append( self.current_bits )
  
                  self.current_bits = 0
                  self.bits_remaining = 8
docs: Push bits into the target.
  
          value
              Integer containing bits to push, ordered from least-significant bit to
              most-significant bit.
  
          count
              Number of bits to push to the target.