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_dec

Converts a string of hexidecimal digits to a decimal value.

dec = hex_to_dec("7B");         //  dec == 123
dec = hex_to_dec("1C8");        //  dec == 456
dec = hex_to_dec("315");        //  dec == 789
hex_to_dec(hex)
Returns an integer converted from an hexadecimal string.
COPY/// @func   hex_to_dec(hex)
///
/// @desc   Returns an integer converted from an hexadecimal string.
///
/// @param  {string}    hex         hexadecimal digits
///
/// @return {real}      positive integer
///
/// GMLscripts.com/license

function hex_to_dec(hex) 
{
    var dec = 0;

    var dig = "0123456789ABCDEF";
    var len = string_length(hex);
    for (var pos = 1; pos <= len; pos += 1) {
        dec = dec << 4 | (string_pos(string_char_at(hex, pos), dig) - 1);
    }

    return dec;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw