def value_to_string(value):
    """Unpack a Verilog-like (but LSB-first) string of unknown width from an integer."""
    msg = bytearray()
    while value:
        byte = value & 0xff
        value >>= 8
        if byte:
            msg.append(byte)
    return msg.decode()
Unpack a Verilog-like (but LSB-first) string of unknown width from an integer.
amaranth/sim/_pyeval.py