parameters: (x)
return_statement: return result
docstring: r"""Encode a long to a two's complement little-endian binary string.
      Note that 0 is a special case, returning an empty string, to save a
      byte in the LONG1 pickling context.
  
      >>> encode_long(0)
      b''
      >>> encode_long(255)
      b'\xff\x00'
      >>> encode_long(32767)
      b'\xff\x7f'
      >>> encode_long(-256)
      b'\x00\xff'
      >>> encode_long(-32768)
      b'\x00\x80'
      >>> encode_long(-128)
      b'\x80'
      >>> encode_long(127)
      b'\x7f'
      >>>
docstring_summary: r"""Encode a long to a two's complement little-endian binary string.
      Note that 0 is a special case, returning an empty string, to save a
      byte in the LONG1 pickling context.
docstring_tokens: r Encode a long to a two s complement little - endian binary string . Note that 0 is a special case returning an empty string to save a byte in the LONG1 pickling context .
function: def encode_long(x):
      r"""Encode a long to a two's complement little-endian binary string.
      Note that 0 is a special case, returning an empty string, to save a
      byte in the LONG1 pickling context.
  
      >>> encode_long(0)
      b''
      >>> encode_long(255)
      b'\xff\x00'
      >>> encode_long(32767)
      b'\xff\x7f'
      >>> encode_long(-256)
      b'\x00\xff'
      >>> encode_long(-32768)
      b'\x00\x80'
      >>> encode_long(-128)
      b'\x80'
      >>> encode_long(127)
      b'\x7f'
      >>>
      """
      if x == 0:
          return b''
      nbytes = (x.bit_length() >> 3) + 1
      result = x.to_bytes(nbytes, byteorder='little', signed=True)
      if x < 0 and nbytes > 1:
          if result[-1] == 0xff and (result[-2] & 0x80) != 0:
              result = result[:-1]
      return result
function_tokens: def encode_long ( x ) : if x == 0 : return b'' nbytes = ( x . bit_length ( ) >> 3 ) + 1 result = x . to_bytes ( nbytes , byteorder = 'little' , signed = True ) if x < 0 and nbytes > 1 : if result [ - 1 ] == 0xff and ( result [ - 2 ] & 0x80 ) != 0 : result = result [ : - 1 ] return result