parameters: (val, bytesize)
return_statement: return bytearray(map(ord, packed))
docstring: Utility function to convert an integer into a bytearray.
  
      It returns the bytearray in the little endian format.  It is easy to get the
      big endian format, just do ba.reverse() on the returned object.
docstring_summary: Utility function to convert an integer into a bytearray.
docstring_tokens: Utility function to convert an integer into a bytearray .
function: def int_to_bytearray(val, bytesize):
      """Utility function to convert an integer into a bytearray.
  
      It returns the bytearray in the little endian format.  It is easy to get the
      big endian format, just do ba.reverse() on the returned object.
      """
      import struct
  
      if bytesize == 1:
          return bytearray([val])
  
      # Little endian followed by a format character.
      template = "<%c"
      if bytesize == 2:
          fmt = template % 'h'
      elif bytesize == 4:
          fmt = template % 'i'
      elif bytesize == 4:
          fmt = template % 'q'
      else:
          return None
  
      packed = struct.pack(fmt, val)
      return bytearray(map(ord, packed))
function_tokens: def int_to_bytearray ( val , bytesize ) : import struct if bytesize == 1 : return bytearray ( [ val ] ) # Little endian followed by a format character. template = "<%c" if bytesize == 2 : fmt = template % 'h' elif bytesize == 4 : fmt = template % 'i' elif bytesize == 4 : fmt = template % 'q' else : return None packed = struct . pack ( fmt , val ) return bytearray ( map ( ord , packed ) )