Why does the format with "% u" print the wrong value when I give it a negative number?

Why does it Format('%u', [-100])lead to '4294967196'? I tested this on D7 and XE2.

the documentation in the function Formatsays:

% u Unsigned decimal point. Similar to% d, but no signs are displayed.

So, I would expect a result like '100'.

This is mistake?

+5
source share
1 answer

No, this is not a mistake.

You say Formatthat the first argument is an unsigned integer, but in fact you passed a signed integer. This signed integer is interpreted as unsigned, and the bit pattern for a value of -100 corresponds to an unsigned value 4294967196.

. , , Format . , , , . , , .

+13

All Articles