Hello all, first time poster here.
I am trying to write a script that can talk to a pascal program. The pascal program creates and write binary files to store compressed data.
The files used in the pascal program are files of "word" (16 bit). Reading and writing works seamlessly. For example, I can write the value 20, then read back the value 20, from such a file.
For example, consider the following code.
program filetesting;
var
f : file of word;
c: integer;
begin
Assign(f, 'wordFile.bin');
Rewrite(f);
Write(f, 20);
Close(f);
assign(f, 'wordFile.bin');
reset(f);
while not eof(f) do
begin
read(f, c);
writeln(c);
end;
end.
This will accurately read and write 20.
However, when opening the binary file with xxd -b wordFile.bin I get
0001010000000000
which is 20, but bitshifted to the left by 8. This seems like really strange behaviour to me. When I rewrite the same program but with bytes
program filetesting;
var
f : file of Byte;
c: byte;
begin
Assign(f, 'wordFile.bin');
Rewrite(f);
Write(f, 20);
Close(f);
assign(f, 'wordFile.bin');
reset(f);
while not eof(f) do
begin
read(f, c);
writeln(c);
end;
end.
I get the correct, single byte binary representation for 20, which is 00010100.
Does anyone have more information on how writing to a file of "word" changes our expectations (not just writing purely binary in chunks of 16 bits)?