Questions regarding endian Byte swapping

  Kiến thức lập trình

I need to write a Python Program that asks for user data, stores them in a binary file and and sends them via socket in binary format to a device.
The data should be transfered in little endian byte order. The following questions arised:
I understand that .to_bytes() with byteorder=’little’ stores the data in RAM in little endian. What if I write these binary data later to a file, Will there be another endian swap in the file depending on the sys.byteorder of the Computer?
What if I open the file with a hex editor, will I see the data how they are or will there be another byte swap when the editor reads the file?
If my program should work Independent to the sys.byteorder of the computer what is the best strategy?
Regards
Sektionschef

So far I saw that .to_bytes() swaps the bytes in memory.

New contributor

Sektionschef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT