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_hex

Converts a decimal value to a string of hexadecimal digits.

hex = dec_to_hex(123);  //  hex == "7B"
hex = dec_to_hex(456);  //  hex == "01C8"
hex = dec_to_hex(789);  //  hex == "0315"
dec_to_hex(dec)
Returns a string of hexadecimal digits (4 bits each) representing the given decimal integer.
COPY/// dec_to_hex(dec)
//
//  Returns a string of hexadecimal digits (4 bits each)
//  representing the given decimal integer. Hexadecimal
//  strings are padded to byte-sized pairs of digits.
//
//      dec         non-negative integer, real
//
/// gmlscripts.pro/license
{
    var dec, hex, h, byte, hi, lo;
    dec = argument0;
    if (dec) hex = "" else hex="00";
    h = "0123456789ABCDEF";
    while (dec) {
        byte = dec & 255;
        hi = string_char_at(h, byte div 16 + 1);
        lo = string_char_at(h, byte mod 16 + 1);
        hex = hi + lo + hex;
        dec = dec >> 8;
    }
    return hex;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw