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

Invert GMLscripts.com

hex_to_bin

Converts a string of hexidecimal digits to a string of binary digits.

bin = hex_to_bin("4");          //  bin == "0100"
bin = hex_to_bin("0E");         //  bin == "00001110"
bin = hex_to_bin("1F");         //  bin == "00011111"
bin = hex_to_bin("55");         //  bin == "01010101"
bin = hex_to_bin("AA");         //  bin == "10101010"
hex_to_bin(hex)
Returns a binary string converted from a hexadecimal string.
COPY/// @func   hex_to_bin(hex)
///
/// @desc   Returns a binary string converted from a hexadecimal string.
///
/// @param  {string}    hex         hexadecimal digits
///
/// @return {string}    binary digits
///
/// GMLscripts.com/license

function hex_to_bin(hex) 
{
    hex = string_upper(hex);
    var bin = "";

    var nib = "0000101100111101000";
    var dig = "0125B6C937FEDA48";
    var len = string_length(hex);
    for (var pos = 1; pos <= len; pos += 1) {
        bin += string_copy(nib, string_pos(string_char_at(hex, pos), dig), 4);
    }
    return bin;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw