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

Aleksa Todorovic alexione at gmail.com
Fri Oct 23 14:16:59 CEST 2009


On Fri, Oct 23, 2009 at 14:10, Graeme Geldenhuys
<graemeg.lists at 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
> of a file, which contains the "magic number" of the file.
>
> I would like my program to output the following:
>
> -----------------
> Header Section
>  header.ID    (5348h = "HS")
>  ...
> -----------------


w: WORD
...
YourString := Chr(Lo(w)) + Chr(Hi(w))
or
YourString := Chr(Hi(w)) + Chr(Lo(w))

(depending on endianness)



>
>
> --
> Regards,
>  - Graeme -
>
>
> _______________________________________________
> fpGUI - a cross-platform Free Pascal GUI toolkit
> http://opensoft.homeip.net/fpgui/
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- 
Aleksa Todorovic - Lead Programmer
Eipix Entertainment
http://www.eipix.com/



More information about the fpc-pascal mailing list