07.12.2016, 11:13
Instead of creating a new thread, I'm asking here.
I created a function (no purpose) which is converting real number (in base 10) to a real number in binary. (ex: 78.347 (10) = 1001110.01011 (2))
My question is : how can I optimize it:
I created a function (no purpose) which is converting real number (in base 10) to a real number in binary. (ex: 78.347 (10) = 1001110.01011 (2))
My question is : how can I optimize it:
PHP код:
DecimalBase10toDecimalBase2(Float:number)
{
new
Float:decimal = 1 - (floatround(number, floatround_ceil) - number),
entier = floatround(number - decimal),
binary[20 + EOS],
rest;
for(new i; i != 8; i++)
{
decimal *= 2.00;
if(decimal > 1.00)
{
decimal -= 1.00;
format(binary, sizeof(binary), "%s1", binary);
}
else
format(binary, sizeof(binary), "%s0", binary);
}
format(binary, sizeof(binary), ".%s", binary);
do
{
rest = entier % 2;
entier /= 2;
if(rest > 0)
format(binary, sizeof(binary), "1%s", binary);
else
format(binary, sizeof(binary), "0%s", binary);
}
while(entier > 0);
return binary;
}