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?
F is 15, not 16.
Pesto
2009-05-19 16:35:13
+10
A:
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.
Pesto
2009-05-19 16:34:47
A:
Probably hexadecimal notation.
The X indicates that the number that follows is hexadecimal (0-9 + A-F).
GvS
2009-05-19 16:36:14
A:
As the comments have stated, StrToInt does not understand octal.
To answer your other question, if there are other strings that return unlikely answers... Try this:
StrToInt('010')
If it returns 8, then that function also understands octal notation.
sharth
2009-05-19 16:40:12
Nope, 010 is converted to 10, it just understands decimal and hexadecimal.
Fabio Gomes
2009-05-19 16:48:21
Marco van de Voort
2009-05-19 20:42:42
+8
A:
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
vcldeveloper
2009-05-20 09:48:35