def _GetFormatCharForStructUnpack(int_width):
  """Gets the sample's integer format char to use with struct.unpack.

  It is assumed that 1-byte width samples are unsigned, all other
  sizes are signed.

  Args:
    int_width: (int) width of the integer in bytes. Can be 1, 2, or 4.

  Returns:
    The format char corresponding to the int described by the
    arguments in the format used by the struct module.

  Raises:
    ValueError: if any of the parameters is invalid.
  """
  is_signed = False if int_width == 1 else True
  format_chars = [None, 'b', 'h', None, 'i']
  if int_width > len(format_chars) or not format_chars[int_width]:
    raise ValueError('Invalid width %d.' % int_width)
  format_char = format_chars[int_width]
  return format_char if is_signed else format_char.upper()