Big Endian file format
-
Is there any way to read Motorolla-style (Big Endian) file formats? The problem is that bytes ordering starts from high byte to low byte, unlike usual (for Windows) from low to high. E.g. if you will write
DWORD
type with value 1 into binary file using any file routines (MFC, API, whatever) you will see in the file such numbers: (in hex display)01 00 00 00
When you'll read it, you will get you "1" back. Now Motorolla style is vise versa:
00 00 00 01
I have such file (actually everyone has it - it is TrueType fonts) and I need to read the numbers in it correctly. Of course when I'm using CFile or file handle to read data, I get different numbers, since it reads it in Windows style :( Any way to override it? Philip Patrick Web-site: www.stpworks.com "Two beer or not two beer?" Shakesbeer Need Web-based database administrator? You already have it!
-
Is there any way to read Motorolla-style (Big Endian) file formats? The problem is that bytes ordering starts from high byte to low byte, unlike usual (for Windows) from low to high. E.g. if you will write
DWORD
type with value 1 into binary file using any file routines (MFC, API, whatever) you will see in the file such numbers: (in hex display)01 00 00 00
When you'll read it, you will get you "1" back. Now Motorolla style is vise versa:
00 00 00 01
I have such file (actually everyone has it - it is TrueType fonts) and I need to read the numbers in it correctly. Of course when I'm using CFile or file handle to read data, I get different numbers, since it reads it in Windows style :( Any way to override it? Philip Patrick Web-site: www.stpworks.com "Two beer or not two beer?" Shakesbeer Need Web-based database administrator? You already have it!
We have done a lot of work rearranging bytes and words between big-endian and little-endian systems. Be careful, though, as usually the difference is not byte reversal, but word (i.e., 2-byte groups) reversal, depending on the processor. A fairly easy approach is to use a structure with high-word and low-word (or bytes, as needed). The read function can read file contents into the big-endian elements of the structure, and then a little-endian value can be constructed by combining those elements in reverse order. Dave "You can say that again." -- Dept. of Redundancy Dept.
-
We have done a lot of work rearranging bytes and words between big-endian and little-endian systems. Be careful, though, as usually the difference is not byte reversal, but word (i.e., 2-byte groups) reversal, depending on the processor. A fairly easy approach is to use a structure with high-word and low-word (or bytes, as needed). The read function can read file contents into the big-endian elements of the structure, and then a little-endian value can be constructed by combining those elements in reverse order. Dave "You can say that again." -- Dept. of Redundancy Dept.
Uff.. lol Well, did it, but it is kinda dissapointing to reverse bytes and words for each member of structure :( Imaging that I have like 5 structures (for now) and about 5 members in each (short or long). I'm rearranging the order for each member. What I thought, maybe there is some "flag" in functions like "CreateFile", etc., which will tell the system to read data in Big endian style. But didn't find nothing, so I guess this is the only way :( Philip Patrick Web-site: www.stpworks.com "Two beer or not two beer?" Shakesbeer Need Web-based database administrator? You already have it!
-
Uff.. lol Well, did it, but it is kinda dissapointing to reverse bytes and words for each member of structure :( Imaging that I have like 5 structures (for now) and about 5 members in each (short or long). I'm rearranging the order for each member. What I thought, maybe there is some "flag" in functions like "CreateFile", etc., which will tell the system to read data in Big endian style. But didn't find nothing, so I guess this is the only way :( Philip Patrick Web-site: www.stpworks.com "Two beer or not two beer?" Shakesbeer Need Web-based database administrator? You already have it!
I agree, if only it were that easy. We run into this problem when reading data from external hardware devices. Many of those are made with an embedded chip and their available output has that chip's byte ordering. May or may not correspond to PCs and Windows, so we have to change it as needed. Unfortunately, I haven't ever seen that nice flag, but it sure would be useful. Good luck, Dave "You can say that again." -- Dept. of Redundancy Dept.