Why does StrToInt('X5') returns 5 in Delphi? Is X some scientific notation or something like it? Are there some other chars which will be converted to Integer as well?
Not knowing Delphi, I'd wager that the "X" causes the function to assume the value is hexidecimal. Since 0x5 == 5, it appears to be working. Try X10 and see if you get back 16.
In Delphi, hexadecimal values are marked with $ prefix:
a := $10; // => a = 16
But since in some other languages (e.g. C) X is used for marking hexadecimal values, StrToInt function supports both $ and X prefixes, so both of the codes below return 16:
a := StrToInt('x10'); // => a = 16
a := StrToInt('$10'); // => a = 16
It's hex notation. Try XF to see it return 15.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With