bin_to_fraction

Downloadbin_to_fraction(str)   Returns the decimal fraction that represents the given binary string.
/*
**  Usage:
**      bin_to_fraction(str)
**
**  Arguments:
**      str     string of binary digits, eg. "11001100"
**
**  Returns:
**      the decimal fraction that represents the given binary string
**
**  GMLscripts.com
*/

{
    var i,ret;
    i = 0;
    ret = 0;
    repeat (string_length(argument0)) {
        if (string_char_at(argument0,i+1) = "1") ret += 1/(2<<i);
        i += 1;
    }
    return ret;
}

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


comments powered by Disqus