Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I posted a question on this issue.
Fault reading data struct on linux[^]

To recapitulate, binary data created on Windows is loaded from Linux. But it doesn't work on Linux.
While contemplating a solution, I wanted to know how binary data would look on Linux.

So I ran hexdump.
The following is the difference between the results on Windows and Linux.
What do I need to do to fix the problem in the results shown?

What I have tried:

hexdump executed on windows
  Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 	
00000000: 01 00 2A 00 0A 00 00 00 03 09 8E 07 00 00 00 80    ..*.............
00000010: 07 00 00 38 04 00 00 5F 01 00 00 01 00 00 00 EB    ...8..._.......k
00000020: E8 00 00 00 00 00 00 00 00 00 00 B8 01 00 00 2F    h..........8.../
00000030: 02 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00    ................
00000040: 4A EA 00 00 02 00 00 00 B2 87 04 00 00 00 00 00    Jj......2.......
00000050: 00 00 00 00 F9 02 00 00 E8 03 00 00 03 00 00 00    ....y...h.......
00000060: 00 00 00 00 00 00 00 00 00 FC 71 05 00 03 00 00    .........|q.....
00000070: 00 19 2B 00 00 00 00 00 00 00 00 00 00 40 01 00    ..+..........@..
00000080: 00 F0 00 00 00 03 00 00 00 00 00 00 00 00 00 00    .p..............
00000090: 00 00 15 9D 05 00 04 00 00 00 80 61 01 00 00 00    ...........a....
000000a0: 00 00 00 00 00 00 80 02 00 00 E0 01 00 00 03 00    ..........`.....
000000b0: 00 00 00 00 00 00 00 00 00 00 00 95 FE 06 00 05    ............~...
000000c0: 00 00 00 F0 6D 08 00 00 00 00 00 00 00 00 00 FC    ...pm..........|
000000d0: 02 00 00 89 05 00 00 03 00 00 00 00 00 00 00 00    ................
000000e0: 00 00 00 00 85 6C 0F 00 06 00 00 00 EE E5 01 00    .....l......ne..
000000f0: 00 00 00 00 00 00 00 00 90 01 00 00 20 02 00 00    ................
00000100: 03 00 00 00 00 00 00 00 00 00 00 00 00 73 52 11    .............sR.
00000110: 00 07 00 00 00 45 DF 03 00 00 00 00 00 00 00 00    .....E_.........
00000120: 00 BC 02 00 00 04 02 00 00 03 00 00 00 00 00 00    .<..............
00000130: 00 00 00 00 00 00 B8 31 15 00 08 00 00 00 80 39    ......81.......9
00000140: 00 00 00 00 00 00 00 00 00 00 F4 01 00 00 3E 01    ..........t...>.
00000150: 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00       ...............


hexdump executed on Linux
0000000 001  \0   *  \0  \n  \0  \0  \0 003  \t 216  \a  \0  \0  \0 200
0000010  \a  \0  \0   8 004  \0  \0   _ 001  \0  \0 001  \0  \0  \0 353
0000020 350  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0 270 001  \0  \0   /
0000030 002  \0  \0 003  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000040   J 352  \0  \0 002  \0  \0  \0 262 207 004  \0  \0  \0  \0  \0
0000050  \0  \0  \0  \0 371 002  \0  \0 350 003  \0  \0 003  \0  \0  \0
0000060  \0  \0  \0  \0  \0  \0  \0  \0  \0 374   q 005  \0 003  \0  \0
0000070  \0 031   +  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0   @ 001  \0
0000080  \0 360  \0  \0  \0 003  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000090  \0  \0 025 235 005  \0 004  \0  \0  \0 200   a 001  \0  \0  \0
00000a0  \0  \0  \0  \0  \0  \0 200 002  \0  \0 340 001  \0  \0 003  \0
00000b0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0 225 376 006  \0 005
00000c0  \0  \0  \0 360   m  \b  \0  \0  \0  \0  \0  \0  \0  \0  \0 374
00000d0 002  \0  \0 211 005  \0  \0 003  \0  \0  \0  \0  \0  \0  \0  \0
00000e0  \0  \0  \0  \0 205   l 017  \0 006  \0  \0  \0 356 345 001  \0
00000f0  \0  \0  \0  \0  \0  \0  \0  \0 220 001  \0  \0     002  \0  \0
0000100 003  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0   s   R 021
0000110  \0  \a  \0  \0  \0   E 337 003  \0  \0  \0  \0  \0  \0  \0  \0
0000120  \0 274 002  \0  \0 004 002  \0  \0 003  \0  \0  \0  \0  \0  \0
0000130  \0  \0  \0  \0  \0  \0 270   1 025  \0  \b  \0  \0  \0 200   9
0000140  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0 364 001  \0  \0   > 001
0000150  \0  \0 003  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0    
000015f
Posted
Updated 8-Apr-21 11:03am
v4
Comments
[no name] 8-Apr-21 14:54pm    
Your Linux "hex" dump looks more like a "character" dump; same data, different presentation.
Rick York 8-Apr-21 16:02pm    
Gerry is right, that is not a hex dump. To fix the problem find a program that runs on linux and dumps data in hexadecimal format. The program you used might do it if you pass it an appropriate argument.
Richard MacCutchan 9-Apr-21 5:35am    
as I suggested in your original question, you ignore the return value from your calls to fread, so you cannot be sure that you actually read any data. And the results certainly give the impression that you did not.

And as already pointed out the data dumps suggest that the file content is exactly the same.

1 solution

Try using xxd on linux to show your binary data as hex:

[k5054@localhost tmp]$ cat hellow.cpp 
#include <iostream>

int main()
{
    std::cout << "Hello World!\n";
}
[k5054@localhost tmp]$ xxd -g1 hellow.cpp 
00000000: 23 69 6e 63 6c 75 64 65 20 3c 69 6f 73 74 72 65  #include <iostre
00000010: 61 6d 3e 0a 0a 69 6e 74 20 6d 61 69 6e 28 29 0a  am>..int main().
00000020: 7b 0a 20 20 20 20 73 74 64 3a 3a 63 6f 75 74 20  {.    std::cout 
00000030: 3c 3c 20 22 48 65 6c 6c 6f 20 57 6f 72 6c 64 21  << "Hello World!
00000040: 5c 6e 22 3b 0a 7d 0a                             \n";.}.
The -g1 parameter groups the output by single bytes, the default is 2. See the man page for details
Update
xxd has a reverse option -r which takes an xxd dump and writes out binary. I took your Windows hex-dump from above, saved it to a file and trimmed off the header.
[k5054@localhost tmp]$ xxd -r data.txt data.bin
[k5054@localhost tmp]$ file data.txt data.bin
data.txt: ASCII text
data.bin: data
[k054@localhost tmp]$ xxd -g1 data.bin
00000000: 01 00 2a 00 0a 00 00 00 03 09 8e 07 00 00 00 80  ..*.............
00000010: 07 00 00 38 04 00 00 5f 01 00 00 01 00 00 00 eb  ...8..._........
00000020: e8 00 00 00 00 00 00 00 00 00 00 b8 01 00 00 2f  .............../
00000030: 02 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000040: 4a ea 00 00 02 00 00 00 b2 87 04 00 00 00 00 00  J...............
00000050: 00 00 00 00 f9 02 00 00 e8 03 00 00 03 00 00 00  ................
00000060: 00 00 00 00 00 00 00 00 00 fc 71 05 00 03 00 00  ..........q.....
00000070: 00 19 2b 00 00 00 00 00 00 00 00 00 00 40 01 00  ..+..........@..
00000080: 00 f0 00 00 00 03 00 00 00 00 00 00 00 00 00 00  ................
00000090: 00 00 15 9d 05 00 04 00 00 00 80 61 01 00 00 00  ...........a....
000000a0: 00 00 00 00 00 00 80 02 00 00 e0 01 00 00 03 00  ................
000000b0: 00 00 00 00 00 00 00 00 00 00 00 95 fe 06 00 05  ................
000000c0: 00 00 00 f0 6d 08 00 00 00 00 00 00 00 00 00 fc  ....m...........
000000d0: 02 00 00 89 05 00 00 03 00 00 00 00 00 00 00 00  ................
000000e0: 00 00 00 00 85 6c 0f 00 06 00 00 00 ee e5 01 00  .....l..........
000000f0: 00 00 00 00 00 00 00 00 90 01 00 00 20 02 00 00  ............ ...
00000100: 03 00 00 00 00 00 00 00 00 00 00 00 00 73 52 11  .............sR.
00000110: 00 07 00 00 00 45 df 03 00 00 00 00 00 00 00 00  .....E..........
00000120: 00 bc 02 00 00 04 02 00 00 03 00 00 00 00 00 00  ................
00000130: 00 00 00 00 00 00 b8 31 15 00 08 00 00 00 80 39  .......1.......9
00000140: 00 00 00 00 00 00 00 00 00 00 f4 01 00 00 3e 01  ..............>.
00000150: 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00     ...............
 
Share this answer
 
v2
Comments
CPallini 9-Apr-21 2:17am    
5.
Chopin2001 9-Apr-21 13:57pm    
k5054 Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900