bin_to_dec
Converts a string of binary digits to a decimal value.
dec = bin_to_dec("00100"); // dec == 4
dec = bin_to_dec("10101"); // dec == 21
dec = bin_to_dec("11111"); // dec == 31
- bin_to_dec(bin)
- Returns a non-negative integer (real) representing the given binary string.
COPY/// bin_to_dec(bin)
//
// Returns a non-negative integer (real)
// representing the given binary string.
//
// bin binary digits, string
//
/// gmlscripts.pro/license
{
var bin, dec, l, p;
bin = argument0;
dec = 0;
l = string_length(bin);
for (p=1; p<=l; p+=1) {
dec = dec << 1;
if (string_char_at(bin, p) == "1") dec = dec | 1;
}
return dec;
}
Contributors: xot
GitHub: View · Commits · Blame · Raw