StringToHex - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: StringToHex (
/showthread.php?tid=350640)
StringToHex -
zgintasz - 13.06.2012
Hi guys,
I searched it, but I didn't find. I need function, that converts string to hex. I know, it's possible with sscanf, but I need to do that
WITHOUT sscanf.
pawn Код:
new
string[ 50 ],
hex
;
format( string, sizeof( string ), "%x%x", 0x000000 , 255 );
sscanf( string, "x", hex );
printf( "%d %x", hex, hex );
I really need this...
Thanks
!
Re: StringToHex -
Vince - 13.06.2012
https://sampwiki.blast.hk/wiki/Colors#Co...alue_with_pawn
Not sure why you'd possibly ever need it. People have some odd views on colors, thinking they are strings and shit.
Re: StringToHex -
zgintasz - 13.06.2012
Thanks for reply, but it doesn't work correctly. I don't know why, here is my test results:
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
In this case,
sscanf works properly. Don't ask, why I need it
.
Re: StringToHex -
MP2 - 13.06.2012
Quote:
Originally Posted by Vince
Not sure why you'd possibly ever need it. People have some odd views on colors, thinking they are strings and shit.
|
For in-game input?