def int_to_string(x):
    """Convert integer x into a string of bytes, as per X9.62."""
    assert x >= 0
    if x == 0:
        return bytearray([0])
    result = bytearray()
    while x > 0:
        q, r = divmod(x, 256)
        result = bytearray([r]) + result
        x = q
    return result
