SA-MP Forums Archive
Algorithm only of numbers - 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: Algorithm only of numbers (/showthread.php?tid=412085)



Algorithm only of numbers - zopert - 31.01.2013

I need the algorithm which converting string (any letters, symbols, numbers) to numbers (can be ASCII). On php I've seen that there are this functions, but on pawn - not.

Hm, what could explain how to write this functions, or explain how to write.
On pawn I'm not novice.
Thanks.


Re: Algorithm only of numbers - zopert - 31.01.2013

Nobody can help?


Re: Algorithm only of numbers - Bakr - 31.01.2013

You can use this table to see the values of each character and then make a custom function: http://www.asciitable.com/

Here is the format of the function (I cannot be bothered to do the whole thing):
pawn Код:
SymbolToASCII(char)
{
    switch(char)
    {
        case ' ': return 32;
        case '!': return 33;
        // etc....
    }
    return -1;
}



Re: Algorithm only of numbers - zopert - 31.01.2013

@Bakr, I wanna encoding not one symbol, I wanna encoding long text, with different symbols, numbers.

Example:
Код:
new Text[126] = "Hello all. 123. @$@%@. {FF0000}Red.";
encodeToASCII(Text); // Print, ex: 46498489498
decodeFromASCII(Text); // Print: Hello all. 123. @$@%@. {FF0000}Red.



Re: Algorithm only of numbers - Bakr - 31.01.2013

Only way I can honestly think of doing this would be to loop through each character in the string then get its corresponding ASCII decimal value, storing that into another string (strcat).

As for the decoding, that is another problem as each character can have different numbers that take more characters to display (i.e. ' ' = 32, 'i' = 105). You would need some sort of delimiter inserted between characters.


Re: Algorithm only of numbers - zopert - 31.01.2013

I have one mind.

I call with HTTP() function .php file from my hosting and on here call php decode/uncode functions.


Re: Algorithm only of numbers - Bakr - 31.01.2013

Yeah, that would work. I've never personally used the HTTP function so cannot say how efficient that would be, but definitely worth trying.


Re: Algorithm only of numbers - zopert - 01.02.2013

Thank you, ******.