Gabriel Reyes
Gabriel Reyes

Reputation: 48

does endianness cause read or write operation conflicts?

As far as I'm concerned, endianness only affects bytes, but I still don't know if it affects individual bits.

I am aware of network byte order. However, I am not sure if there is a standard for input or file I/O. More specifically, something like NES ROM emulator / decoder. Suppose The NES being little endian in nature, flipped all of it's bits, and then the programmer of a NES emulator on a big endian machine, would not realize that those bits need to be reversed in order to proceed.

Of course that wouldn't be an issue if there was a standard for reading static data of files.

If a little endian machine wrote data to a file. Intuitively, I can't help to assume those bits to be stored backwards. ( I know for sure that guaranteed the bytes would be in reverse order)

So if a little endian machine writes data to say, a ROM file, does that mean that all of it's bits must be flipped in order for the big endian machine to read it?

Upvotes: 0

Views: 664

Answers (2)

If I understand correctly, you are asking whether there is a possibility that a file transferred from another machine might have the bits reversed in each byte (10110000 -> 00001101) and if not, why not.

Files are defined to be made of bytes (that's a definition made up by people). Whenever you copy a file, the copy has the same bytes as the original. If this didn't happen, then we telephone the person who wrote the copy program, and call them a moron. People who write copy programs don't want to be called morons, so they make sure their copy program copies bytes properly.

This is also true when files are transferred between two different systems. The people who designed the network don't want to be called morons either, so they made sure that the computers at each end of a network know which end of a byte is the high end, and which end is the low end. Ethernet sends bits in little-endian order, but it doesn't matter since you never actually see the bits in any order - you only see whole bytes.

If you use a floppy disk (remember those?), the people who designed floppy disks also don't want to be called morons, so they made sure that all the computers that use a floppy disk put the bits in the same order within each byte... see the pattern?

When someone designs a circuit to dump NES ROMs, they do the same thing. They make sure that if the NES sees a byte as 10110000 then so will the computer. It doesn't matter if the NES has the MSB on the left side of its circuit board and the computer has the MSB on the right side of its circuit board - that just means the designer has to swap the wires around (or make a note for the software writers to do it). If that doesn't happen, then the NES dumper circuit is declared broken. And the person who made the circuit telephones themself and calls themself a moron for making a broken circuit, and then they fix it.

It's possible that they dump the bits in the wrong order deliberately, to make the circuit simpler, but we still call it wrong and we know that the software has to fix it before it saves the ROM data to your hard disk.

Upvotes: 0

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385385

Endianness is about the order of bytes in a block.

Your bits on one system:

 byte 1   byte 2   byte 3
ABCDEFGH IJKLMNOP QRSTUVWX

will look like this instead on a system with the opposite endianness (middle-endianness exists too but let's ignore that for a moment) until you correct for it:

 byte 1   byte 2   byte 3
QRSTUVWX IJKLMNOP ABCDEFGH

So the bytes are being read in a different order, but the values of each byte individually have not changed.

However, if integers are represented on one platform in one way (say, two's complement) and on another platform in another way (say, one's complement), the bits that make up an integer won't be portable between those platforms even if you account for endianness differences. You would have to account for that yourself.

Upvotes: 3

Related Questions