def number_to_bytes(n, endian='<STR_LIT>'):
res = []<EOL>while n:<EOL><INDENT>n, ch = divmod(n, <NUM_LIT>)<EOL>if PY3:<EOL><INDENT>res.append(ch)<EOL><DEDENT>else:<EOL><INDENT>res.append(chr(ch))<EOL><DEDENT><DEDENT>if endian == '<STR_LIT>':<EOL><INDENT>res.reverse()<EOL><DEDENT>if PY3:<EOL><INDENT>return bytes(res)<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT>'.join(res)<EOL><DEDENT>
Convert an integer to a corresponding string of bytes..

:param n:
    Integer to convert.

:param endian:
    Byte order to convert into ('big' or 'little' endian-ness, default
    'big')

Assumes bytes are 8 bits.

This is a special-case version of number_to_string with a full base-256
ASCII alphabet. It is the reverse of ``bytes_to_number(b)``.

Examples::

    >>> r(number_to_bytes(42))
    b'*'
    >>> r(number_to_bytes(255))
    b'\\xff'
    >>> r(number_to_bytes(256))
    b'\\x01\\x00'
    >>> r(number_to_bytes(256, endian='little'))
    b'\\x00\\x01'