13.06.2012, 10:07
Thanks for reply, but it doesn't work correctly. I don't know why, here is my test results:
In this case, sscanf works properly. Don't ask, why I need it .
pawn Код:
new
string[ 50 ],
hex
;
format( string, sizeof( string ), "%x%x", 0xFF0000, 17 );
sscanf( string, "x", hex );
printf( "sscanf: %d %x", hex, hex );
hex = HexToInt( string );
printf( "HexToInt: %d %x", hex, hex );
// above
stock HexToInt(string[])
{
if (string[0] == 0)
{
return 0;
}
new i;
new cur = 1;
new res = 0;
for (i = strlen(string); i > 0; i--)
{
if (string[i-1] < 58)
{
res = res + cur * (string[i - 1] - 48);
}
else
{
res = res + cur * (string[i-1] - 65 + 10);
cur = cur * 16;
}
}
return res;
}
Код:
[13:13:41] sscanf: -16777199 -FFFFEF [13:13:41] HexToInt: 257 101