richard.kerry@quantel.com wrote:
Does gpc have a built-in mechanism for converting a number to hexadecimal, for use in write(ln) or just as a number to string conversion ?
Not yet, AFAIK.
Oregon Pascal uses a negative field width to denote hex output (which I believe is sometimes also used to denote left justification),
Not in GPC (currently, anyway).
I agree that both hex output (or more generally, output with arbitrary base) and left justification are useful features.
Since I've just hacked almost all of the read and write routines, it would be no big deal to built them in the RTS, if wanted. The only question remaining is about the syntax.
Obviously, not both can use negative field widths, and anyway, negative field withs are not very clear (neither to someone new, nor in comparison to other compilers that behave differently).
Something that seems possible would be to use a second specifier (as real numbers have for the precision). Then, "write(42:5:16)" would produce " 2A". Now, should we use upper or lower case letters? Perhaps a compiler switch?
For left justification, we could make another compiler switch, or indeed use negative field widths. The latter would make it easier to mix right and left justified output (which might be desirable).
and Vax Pascal has a built-in 'hex( num, width )'.
Such a function can, of course, be written in pure Pascal, if needed. (But it would duplicate some code that's similar in the RTS...)