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 a decimal integer (real) representing the given hexadeciaml string.
COPY/// hex_to_dec(hex)
//
//  Returns a decimal integer (real)
//  representing the given hexadeciaml string.
//
//      hex         hexadecimal digits, string
//
/// GMLscripts.com/license
{
    var hex, dec, h, p;
    hex = string_upper(argument0);
    dec = 0;
    h = "0123456789ABCDEF";
    for (p=1; p<=string_length(hex); p+=1) {
        dec = dec << 4 | (string_pos(string_char_at(hex, p), h) - 1);
    }
    return dec;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw