code: def _long_to_bytes(n, length, byteorder):
      
      if byteorder == 'little':
          indexes = range(length)
      else:
          indexes = reversed(range(length))
      return bytearray((n >> i * 8) & 0xff for i in indexes)
docs: Convert a long to a bytestring
      For use in python version prior to 3.2
      Source:
      http://bugs.python.org/issue16580#msg177208