fraction_to_bin
/*
** Usage:
** fraction_to_bin(value,size)
**
** Arguments:
** value fraction to convert
** size number of bits, use more for accuracy
**
** Returns:
** a string of binary digits representing the given decimal fraction
**
** GMLscripts.com
*/
{
var i,ret;
i = 0;
ret = "";
repeat (argument1) {
if (argument0 >= 1/(2<<i)) {
ret += "1";
argument0 -= 1/(2<<i);
}else{
ret += "0";
}
i += 1;
}
return ret;
}
** Usage:
** fraction_to_bin(value,size)
**
** Arguments:
** value fraction to convert
** size number of bits, use more for accuracy
**
** Returns:
** a string of binary digits representing the given decimal fraction
**
** GMLscripts.com
*/
{
var i,ret;
i = 0;
ret = "";
repeat (argument1) {
if (argument0 >= 1/(2<<i)) {
ret += "1";
argument0 -= 1/(2<<i);
}else{
ret += "0";
}
i += 1;
}
return ret;
}
[Please Login]
Projects: 4
Contributor: Bryan
comments powered by Disqus

Related: