Hi,
I understand this isn't necessarily related to the NES, but this is "General Stuff", right?
Basically, I've been in need of a program that can byte-swap files from start to end (big-endian to little-endian and vice versa). I am using a hex editor, but it doesn't seem to be able to do such a thing. This program should be free, and preferably open-source as well. Maybe you could program it yourself if you can't find any tool. I'm not good enough at coding yet.
Byte-swap tool for Windows?
Moderator: Moderators
-
- Posts: 1565
- Joined: Tue Feb 07, 2017 2:03 am
Re: Byte-swap tool for Windows?
Okay lets imagine I have a file of 6 bytes
00 01 02 03 04 05
this is both little endian and big endian.
Okay lets imagine I have a file of 3 words
00 01 02 03 04 05
now let change the endian
01 00 03 02 05 04
Okay lets imagine I have a file of 2 longs
00 01 02 03 04 05
now lets change the endian
02 01 00 05 04 03
okay which way is the right way to flip it? Byte, Word or Long?
You have to understand the size of each element in the file and change the endian correctly for each item on an item per item basis. There is to my knowledge no tool to do this, as you have to make a file the specifies what each "item" is and then it has to parse and well that kind of something nobody really ever does without having the source code to read it already..
why do you need to change the endienes of a file? If you use something like Transhexlation it will convert a byte,word,long value from the hex in either Motorola or Intel so you can read it, but it won't actually change the hex file it self.
00 01 02 03 04 05
this is both little endian and big endian.
Okay lets imagine I have a file of 3 words
00 01 02 03 04 05
now let change the endian
01 00 03 02 05 04
Okay lets imagine I have a file of 2 longs
00 01 02 03 04 05
now lets change the endian
02 01 00 05 04 03
okay which way is the right way to flip it? Byte, Word or Long?
You have to understand the size of each element in the file and change the endian correctly for each item on an item per item basis. There is to my knowledge no tool to do this, as you have to make a file the specifies what each "item" is and then it has to parse and well that kind of something nobody really ever does without having the source code to read it already..
why do you need to change the endienes of a file? If you use something like Transhexlation it will convert a byte,word,long value from the hex in either Motorola or Intel so you can read it, but it won't actually change the hex file it self.
Re: Byte-swap tool for Windows?
For the specific instance of byte-swapping 16-bit words (i.e. ABCD becomes BADC), the extremely ancient and open-source program dd can do that using conv=swab.
Re: Byte-swap tool for Windows?
What are you actually trying to do?
Re: Byte-swap tool for Windows?
My program utftovlq can do that; use utftovlq wW to swap endianness of 16-bit words (you can also swap 32-bit words with utftovlq dD, but not 24-bit) (Windows executable is not provided, but you could compile it yourself)
(Free Hero Mesh - FOSS puzzle game engine)
- TmEE
- Posts: 960
- Joined: Wed Feb 13, 2008 9:10 am
- Location: Norway (50 and 60Hz compatible :P)
- Contact:
Re: Byte-swap tool for Windows?
All the MD ROMs have reverse byte order compared to what pretty much all EPROM programmers expect.Oziphantom wrote:why do you need to change the endienes of a file? If you use something like Transhexlation it will convert a byte,word,long value from the hex in either Motorola or Intel so you can read it, but it won't actually change the hex file it self.
Re: Byte-swap tool for Windows?
You can do this pretty easily with Python (free and open source) with something like this for 16-bit words:
In fact, you can extend it to work with an arbitrary word size like this:
Code: Select all
with open('input.bin', 'rb') as input_file, open('output.bin', 'wb') as output_file:
data = input_file.read()
for i in range(0, len(data), 2):
high = data[i]
low = data[i + 1]
output_file.write(low)
output_file.write(high)
Code: Select all
input_file_name = 'input.bin'
output_file_name = 'output.bin'
word_size = 2
with open(input_file_name, 'rb') as input_file, open(output_file_name, 'wb') as output_file:
while True:
word = input_file.read(word_size)
if not word:
break
output_file.write(word[::-1])
http://zutanogames.com/ <-- my dev blog