fraction_to_bin

Downloadfraction_to_bin(value,size)   Returns a string of binary digits representing the given decimal fraction.
/*
**  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;
}

Click if you've used this script[Please Login]
Projects: 4


comments powered by Disqus