Changing endian format in a python file | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Changing endian format in a python file

Hi, is there a way to change the endianness (big or little) of the entire python file? My computer's default is little and I want all of the variables in my file big. If not, what is the quickest and simplest way of converting each number to big endian? Thanks a lot

28th Jun 2023, 10:31 AM
Afek Kalmani
Afek Kalmani - avatar
3 Answers
+ 4
Afek Kalmani , > please do a try with google for *python little or big endian*. you will find a lot of information about this topic, especially from stackoverflow.com, and you have to invest some time and effort on getting the particular information that you need.
28th Jun 2023, 1:04 PM
Lothar
Lothar - avatar
+ 2
Thanks, I did search, but apparently what I searched for, and what I asked, are both wrong in their meaning. I searched for an endian as a characteristic, but computers don't work like that. I got it somehow, thanks for trying to help :)
28th Jun 2023, 3:52 PM
Afek Kalmani
Afek Kalmani - avatar
+ 1
convert endianness... That's a rare one. from StackOverflow: (no guarantee, test first to see if it works.) with open(fileName, "rb") as f: arrayName = numpy.fromfile(f, numpy.float32) arrayName.byteswap(True) thread: https://stackoverflow.com/questions/1632673/JUMP_LINK__&&__python__&&__JUMP_LINK-file-slurp-w-endian-conversion
28th Jun 2023, 3:16 PM
Bob_Li
Bob_Li - avatar