SA-MP Forums Archive
HexToDec won't work - 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: HexToDec won't work (/showthread.php?tid=604823)



HexToDec won't work - Maxandmov - 10.04.2016

Код:
public HexToDec(hex[])
public HexToDec(hex[])
{
    new st[1];
	new result,Float:in;
    result = 0;
    in = 0;
    while(strlen(hex) != 0)
    {
		//strins(st, hex[strlen(hex)-1], 0, 1);
		strmid(st, hex, strlen(hex), strlen(hex));
		strdel(hex,strlen(hex)-1,strlen(hex));
		result = result + GetVal(st)*floatround(floatpower(16, in),floatround_ceil);
		in = in+1;
    }
    return result;
}
Ok, so I have some color I input in this public. It is formatted RRGGBB. So I take each symbol from there, but the thing is every time prinf claims my symbol I get with strmid is nothing. What am I doing wrong, my friends?


Re: HexToDec won't work - AbyssMorgan - 10.04.2016

PHP код:
stock HexToInt(string[]){
    if(
string[0] == 0) return 0;
    new 
cur 1res 0;
    for(new 
strlen(string)-1>= 0i--){
        if(
string[i] < 58){
            
res res cur * (string[i] - 48);
        } else {
            
res res cur * (string[i] - 55);
        }
        
cur cur 16;
    }
    return 
res;




Re: HexToDec won't work - Maxandmov - 10.04.2016

I'll check it out now.

P.S. Wow that's fast!


Re: HexToDec won't work - Darkwood17 - 10.04.2016

https://sampwiki.blast.hk/wiki/Colors_Li...alue_with_pawn


Re: HexToDec won't work - Maxandmov - 10.04.2016

It works, thanks a lot