There is an input parameter MinWidth, which is responsible for the minimum number of output characters of a converted number. Any the number can take up one or more characters. But still, ASSERT inside this procedure also allows the value of MinWidth = 0
Code: Select all
ASSERT(minWidth >= 0, 22);
I was recently forced to write such code:
Code: Select all
PROCEDURE WriteHex(i: INTEGER);
VAR minWidth: INTEGER;
BEGIN
IF i > 9FFFH THEN minWidth := 5
ELSIF i > 9FFH THEN minWidth := 4
ELSIF i > 9FH THEN minWidth := 3
ELSIF i > 9H THEN minWidth := 2
ELSE minWidth := 1
END;
W.WriteIntForm(i, TextMappers.hexadecimal, minWidth, "0", FALSE)
END WriteHex;
And this behavior can be demanded quite often, so I suggest that with MinWidth = 0, implement exactly this behavior as encoded in my procedure: a hexadecimal number with an insignificant zero is output if this number starts with a letter. What do you think, colleagues?