def timestamp_to_bytestring(val, padding=8):
    """Convert Unix timestamp to bytes"""
    result = []

    while val != 0:
        result.append(chr(val & 0xFF))
        val = val >> 8

    return ''.join(reversed(result)).rjust(padding, '\0')