bin_to_dec

Downloadbin_to_dec(bin)   Returns a non-negative integer converted from the given string of binary digits.
/*
**  Usage:
**      bin_to_dec(bin)
**
**  Arguments:
**      bin     a string of binary digits, one bit per character
**
**  Returns:
**      a non-negative integer
**
**  GMLscripts.com
*/

{
    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;
}

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


comments powered by Disqus