Helpful Information
 
 
Category: Delphi Programming
Binary record says what?

Hi!

This is not a Delphi question, but a Pascal question, but since Delphi is a sub language to Pascal I think it will fit in to this forum. :)

I'm storing a record ( one record ) in a file;


TYPE
posttype = RECORD
id : Integer;
name : Packed Array[1..10] Of Char;
data: Integer;
END;

The binary value of this record in the file on the harddrive looks like this:


0000 0000 0000 0000 0000 0000 1000 1101
0101 0011 0111 0100 0110 0101 0111 0111
0110 0001 0111 0010 0111 0100 0010 0000
0010 0000 0010 0000 0000 0000 0000 0000
1111 1111 1111 1111 1111 1111 1111 1011

( Of course without the spaces )

What does this mean? How can I read this in plain english?

Thanks in advance. :)

Regards,

Looks like a hex dump that you're showing there. Two hex digits represent the contents of one byte. Depending on your compiler, integer may be 2 or 4 bytes or whatever (16 bit vs. 32 bit vs. 64 bit of whatever the size of integer may be).

The packed keyword is to tell the compiler to squeeze the bits of a array as close together as possible. For example, ASCII chars are only 7 bits long, and if your byte is 8 bits long (on the original machine that Pascal was implemented in, it was something other than 8 bits to the byte), you could use the unused bits of the byte to store part of the next character in the array. Thus, if you squeezed all the bits together, you might save a few bytes in an array. IIRC Turbo Pascal ignored the packed keyword altogether and was perfectly happy wasting the unused bit per byte, so each character in an array would occupy precisely one byte, and it would leave the high bit of each byte unused. So, even if you have the same data in a packed array, different compilers may give you a different hex dump depending on whether they choose to obey or ignore the packed keyword for the array.










privacy (GDPR)