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

Invert gmlscripts.pro

dec_to_bin

Converts a decimal value to a string of binary digits.

bin = dec_to_bin(123);  //  bin == "1111011"
bin = dec_to_bin(456);  //  bin == "111001000"
bin = dec_to_bin(789);  //  bin == "1100010101"
dec_to_bin(dec)
Returns a string of binary digits (1 bit each) representing the given decimal integer.
COPY/// dec_to_bin(dec)
//
//  Returns a string of binary digits (1 bit each)
//  representing the given decimal integer.
//
//      dec         non-negative integer, real
//
/// gmlscripts.pro/license
{
    var dec, bin;
    dec = argument0;
    if (dec) bin = "" else bin="0";
    while (dec) {
        bin = string_char_at("01", (dec & 1) + 1) + bin;
        dec = dec >> 1;
    }
    return bin;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw