Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-25 Thread Paul Nicholls
- Original Message - From: Graeme Geldenhuys graemeg.li...@gmail.com To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org Sent: Friday, October 23, 2009 11:10 PM Subject: [fpc-pascal] WORD (2 bytes) to String conversion Hi, I'm reading in a WORD (2 bytes) from a binary

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-25 Thread M Pulis
On Oct 25, 2009, at 3:09 PM, Paul Nicholls wrote: - Original Message - From: Graeme Geldenhuys graemeg.li...@gmail.com To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org Sent: Friday, October 23, 2009 11:10 PM Subject: [fpc-pascal] WORD (2 bytes) to String conversion

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Vincent Snijders
Graeme Geldenhuys schreef: On 23/10/2009, Vincent Snijders vsnijd...@vodafonevast.nl wrote: You can consider declaring the ID in the header record type as array[1..2] of char. As Marco suggested... Char size might not always be the same. I did however change my header to array[0..1] of byte

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Graeme Geldenhuys
2009/10/24 Vincent Snijders vsnijd...@vodafonevast.nl: But then you still cannot do: if header.id='HS' then  // magic is correct. That is why I proposed a static array of char. No, but I can do this... which is sufficient. var s: string begin s := hdr^.ID; if S = HS then ...

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Vincent Snijders
Graeme Geldenhuys schreef: 2009/10/24 Vincent Snijders vsnijd...@vodafonevast.nl: But then you still cannot do: if header.id='HS' then // magic is correct. That is why I proposed a static array of char. No, but I can do this... which is sufficient. var s: string begin s := hdr^.ID;

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-24 Thread Jürgen Hestermann
As Marco suggested... Char size might not always be the same. Why that? I hope noone changes the meaning of such long-time types some day. If a new type is needed, then it should get a new name too. ___ fpc-pascal maillist -

[fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
Hi, I'm reading in a WORD (2 bytes) from a binary file. I can display the Hex format of that value without a problem, but I would also like to display the String value of that WORD variable. It's the first 2 bytes of a file, which contains the magic number of the file. I would like my program to

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Aleksa Todorovic
On Fri, Oct 23, 2009 at 14:10, Graeme Geldenhuys graemeg.li...@gmail.com wrote: Hi, I'm reading in a WORD (2 bytes) from a binary file. I can display the Hex format of that value without a problem, but I would also like to display the String value of that WORD variable. It's the first 2 bytes

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
2009/10/23 Aleksa Todorovic alexi...@gmail.com: w: WORD ... YourString := Chr(Lo(w)) + Chr(Hi(w)) or YourString := Chr(Hi(w)) + Chr(Lo(w)) Ah, thanks. I was close, I used High() and Low() instead. :-( Dope! -- Regards, - Graeme - ___

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Jeff Wormsley
Graeme Geldenhuys wrote: Hi, I'm reading in a WORD (2 bytes) from a binary file. I can display the Hex format of that value without a problem, but I would also like to display the String value of that WORD variable. It's the first 2 bytes of a file, which contains the magic number of the file.

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Jeff Wormsley dawor...@comcast.net wrote: That's dangerous, though, if your magic number's two bytes aren't printable That should never be a problem for my tool though. The tool I am writing is specific to the INF help format. The tool dumps the file structure to a text file. (I

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Jeff Wormsley
Graeme Geldenhuys wrote: On 23/10/2009, Jeff Wormsley dawor...@comcast.net wrote: That's dangerous, though, if your magic number's two bytes aren't printable That should never be a problem for my tool though. The tool I am writing is specific to the INF help format.

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Jeff Wormsley dawor...@comcast.net wrote: Oh, I was fairly certain of that. Its just these little routines tend to end up in libraries of handy code. I tend to be overly cautious with some of these because of that. Point taken. :-) This code is purposely rewritten and

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Jürgen Hestermann
I would like my program to output the following: - Header Section header.ID(5348h = HS) ... - Wouldn't it be more direct to use Blockwrite(file,header.ID,sizeof(header.ID)); That would make it robust against changes of ID size and would avoid the many

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Jürgen Hestermann juergen.hesterm...@gmx.de wrote: Wouldn't it be more direct to use Blockwrite(file,header.ID,sizeof(header.ID)); I read the complete header structure in one go (155 bytes). I simply want to output to a text file, a human readable structure of the complete INF

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Vincent Snijders
Graeme Geldenhuys schreef: On 23/10/2009, Jürgen Hestermann juergen.hesterm...@gmx.de wrote: Wouldn't it be more direct to use Blockwrite(file,header.ID,sizeof(header.ID)); I read the complete header structure in one go (155 bytes). I simply want to output to a text file, a human readable

Re: [fpc-pascal] WORD (2 bytes) to String conversion

2009-10-23 Thread Graeme Geldenhuys
On 23/10/2009, Vincent Snijders vsnijd...@vodafonevast.nl wrote: You can consider declaring the ID in the header record type as array[1..2] of char. As Marco suggested... Char size might not always be the same. I did however change my header to array[0..1] of byte instead. -- Regards, -