bin_to_fraction
/*
** 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;
}
** 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;
}
[Please Login]
Projects: 4
Contributor: Bryan
comments powered by Disqus

Related: