October 29th, 2003, 04:35 PM
Binary record says what?
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;
The binary value of this record in the file on the harddrive looks like this:
posttype = RECORD
id : Integer;
name : Packed Array[1..10] Of Char;
( Of course without the spaces )
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
What does this mean? How can I read this in plain english?
Thanks in advance.
October 29th, 2003, 11:29 PM
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.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo