491 def format_value(self, value, check=True):
492 """Format scalar value change for VCD stream.
493
494 :param value: 1-bit (4-state) scalar value.
495 :type value: str, bool, int, or None
496 :raises ValueError: for invalid *value*.
497 :returns: string representing value change for use in a VCD stream.
498
499 """
500 if isinstance(value, str):
501 if check and (len(value) != 1 or value not in '01xzXZ'):
502 raise ValueError(f'Invalid scalar value ({value})')
503 return value + self.ident
504 elif value is None:
505 return 'z' + self.ident
506 elif value:
507 return '1' + self.ident
508 else:
509 return '0' + self.ident
510
511