original_docstring: 
          Perform bit conversion.
          The function takes the input data (list of integers or byte sequence) and convert every value from
          the specified number of bits to the specified one.
          It returns a list of integer where every number is less than 2^to_bits.
  
          Args:
              data (list[int] or bytes): Data to be converted
              from_bits (int)          : Number of bits to start from
              to_bits (int)            : Number of bits to end with
              pad (bool, optional)     : True if data must be padded with zeros, false otherwise
  
          Returns:
              list[int]: List of converted values, None in case of errors
          
docstring: Perform bit conversion.
  The function takes the input data (list of integers or byte sequence) and convert every value from
  the specified number of bits to the specified one.
  It returns a list of integer where every number is less than 2^to_bits.
docstring_tokens: Perform bit conversion . The function takes the input data ( list of integers or byte sequence ) and convert every value from the specified number of bits to the specified one . It returns a list of integer where every number is less than 2^to_bits .
code: def ConvertBits(data: Union[bytes, List[int]],
                      from_bits: int,
                      to_bits: int,
                      pad: bool = True) -> Optional[List[int]]:
          """
          Perform bit conversion.
          The function takes the input data (list of integers or byte sequence) and convert every value from
          the specified number of bits to the specified one.
          It returns a list of integer where every number is less than 2^to_bits.
  
          Args:
              data (list[int] or bytes): Data to be converted
              from_bits (int)          : Number of bits to start from
              to_bits (int)            : Number of bits to end with
              pad (bool, optional)     : True if data must be padded with zeros, false otherwise
  
          Returns:
              list[int]: List of converted values, None in case of errors
          """
          max_out_val = (1 << to_bits) - 1
          max_acc = (1 << (from_bits + to_bits - 1)) - 1
  
          acc = 0
          bits = 0
          ret = []
  
          for value in data:
              # Value shall not be less than zero or greater than 2^from_bits
              if value < 0 or (value >> from_bits):
                  return None
              # Continue accumulating until greater than to_bits
              acc = ((acc << from_bits) | value) & max_acc
              bits += from_bits
              while bits >= to_bits:
                  bits -= to_bits
                  ret.append((acc >> bits) & max_out_val)
          if pad:
              if bits:
                  # Pad the value with zeros to reach to_bits
                  ret.append((acc << (to_bits - bits)) & max_out_val)
          elif bits >= from_bits or ((acc << (to_bits - bits)) & max_out_val):
              return None
  
          return ret
code_tokens: def ConvertBits ( data : Union [ bytes , List [ int ] ] , from_bits : int , to_bits : int , pad : bool = True ) -> Optional [ List [ int ] ] : max_out_val = ( 1 << to_bits ) - 1 max_acc = ( 1 << ( from_bits + to_bits - 1 ) ) - 1 acc = 0 bits = 0 ret = [ ] for value in data : if value < 0 or ( value >> from_bits ) : return None acc = ( ( acc << from_bits ) | value ) & max_acc bits += from_bits while bits >= to_bits : bits -= to_bits ret . append ( ( acc >> bits ) & max_out_val ) if pad : if bits : ret . append ( ( acc << ( to_bits - bits ) ) & max_out_val ) elif bits >= from_bits or ( ( acc << ( to_bits - bits ) ) & max_out_val ) : return None return ret
short_docstring: Perform bit conversion.
short_docstring_tokens: Perform bit conversion .
comment: """
          Perform bit conversion.
          The function takes the input data (list of integers or byte sequence) and convert every value from
          the specified number of bits to the specified one.
          It returns a list of integer where every number is less than 2^to_bits.
  
          Args:
              data (list[int] or bytes): Data to be converted
              from_bits (int)          : Number of bits to start from
              to_bits (int)            : Number of bits to end with
              pad (bool, optional)     : True if data must be padded with zeros, false otherwise
  
          Returns:
              list[int]: List of converted values, None in case of errors
          """$SEP$# Value shall not be less than zero or greater than 2^from_bits$SEP$# Continue accumulating until greater than to_bits$SEP$# Pad the value with zeros to reach to_bits