[fpc-pascal] WORD (2 bytes) to String conversion
Jeff Wormsley
daworm10 at comcast.net
Fri Oct 23 15:27:04 CEST 2009
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.
>
Personally, I'd do something like this, as it is more explicit (you
won't be left wondering what "magic" occurred later:
function WordToString(w: word): String;
begin
Result := Char(hi(w)) + Char(lo(w));
end;
That's dangerous, though, if your magic number's two bytes aren't
printable ASCII. I believe there is an RTL function like
IsPrintableASCII or something like that that you could check each
character with.
Jeff.
--
I haven't smoked for 3 years, 2 months and 6 days, saving $5,235.38 and
not smoking 34,902.58 cigarettes.
More information about the fpc-pascal
mailing list