Binary form of strings
#3

Quote:
Originally Posted by Crayder
View Post
Perhaps it's a lot easier than that? Something like this:
pawn Code:
stock StringToBinary(str[]) {
    new
        dest[500]
    ;
    for(new i, l = strlen(str); i < l; i++) {
        new bits[8];
        for(new d; d < 8; d++)
            bits[d] = ((1 << d) & str[i]) != 0 ? 1 : 0;
       
        strcat(dest, bits);
    }
}

On a another note, shouldn't your first while loop be a do-while?
No valid characters are printed when i performed a similar test:
pawn Code:
StringToBinary("Test");
And actually the problem is not the method but extracting the numerals into a var, how can i directly put the values into a var or array without using strval, because strval works on very less bytes limit.
Reply


Messages In This Thread
Binary form of strings - by Gammix - 07.09.2015, 06:17
Re: Binary form of strings - by Crayder - 07.09.2015, 07:24
Re: Binary form of strings - by Gammix - 07.09.2015, 07:33
Re: Binary form of strings - by Crayder - 07.09.2015, 07:42
Re: Binary form of strings - by Gammix - 07.09.2015, 08:03
Re: Binary form of strings - by Crayder - 07.09.2015, 08:12
Re: Binary form of strings - by Gammix - 07.09.2015, 08:18
Re: Binary form of strings - by Crayder - 07.09.2015, 16:24
Re: Binary form of strings - by maddinat0r - 07.09.2015, 18:36
Re: Binary form of strings - by Mauzen - 10.09.2015, 01:45

Forum Jump:


Users browsing this thread: 1 Guest(s)