You are currently viewing the gmlscripts.pro static mirror. Forum access and script submissions are not available through this mirror.

Invert gmlscripts.pro

bin_to_fraction

Converts a string of binary digits to a fractional value.

val = bin_to_fraction("00100");  //  val == 0.12500
val = bin_to_fraction("10101");  //  val == 0.65625
val = bin_to_fraction("11111");  //  val == 0.96875
bin_to_fraction(bin)
Returns a decimal fraction (real) representing the given binary string.
COPY/// bin_to_fraction(bin)
//
//  Returns a decimal fraction (real)
//  representing the given binary string.
//
//      bin         binary digits, string
//
/// gmlscripts.pro/license
{
    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;
}

Contributors: Bryan

GitHub: View · Commits · Blame · Raw