07.09.2015, 06:17
(
Last edited by Gammix; 07/09/2015 at 06:49 AM.
)
I have been trying this for a while and have failed to extract them values.
Just to those who don't know what i am doing: This is discussion for converting a string into an integer form (0 and 1 only).
Here is my code:
When i use it to for test:
The results are not good:
The problem is that strval somehow limits the characters or its not having high bytes rate. Where as the binary form is doing very well. As you can see the 1st result as a string, it prints all the characters but i can't use it for int vars or arrays.
For example i want to do something like this:
So after putting the result into a var then i will extract it using my inverse function: BinaryToString.
Does anyone have a good String to Binary converter supporting PAWN or any solution?
Just to those who don't know what i am doing: This is discussion for converting a string into an integer form (0 and 1 only).
Here is my code:
pawn Code:
stock StringToBinary(str[]) {
new
dest[500]
;
for(new i = 0, l = strlen(str); i < l; i++) {
new
total = 0,
ascii = str[i],
binary[8]
;
while (ascii > 0) {
if ((ascii % 2) == 0) {
binary[total] = 0;
}
else {
binary[total] = 1;
}
ascii /= 2;
total += 1;
}
total -= 1;
while (total >= 0) {
format(dest, sizeof(dest), "%s%i", dest, binary[total]);
total -= 1;
}
}
printf("Print as a string: %s", dest);
printf("Print with strval: %i", strval(dest));
}
pawn Code:
StringToBinary("Test");
pawn Code:
Print as a string: 1010100110010111100111110100
Print with strval: 132202452
For example i want to do something like this:
pawn Code:
new binnary = StringToBinary("Test");
Does anyone have a good String to Binary converter supporting PAWN or any solution?