Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

dec2hex

By Daniel · January 11, 2009

Returns a hexadecimal string representation of some integer (which should be given as a real, not a string).

/* dec2hex(int)
 *
 * Returns a hexadecimal string representation of some integer (which
 * should be given as a real, not a string).
 */

var lang, neg, hex;

lang = '0123456789ABCDEF';
neg = (argument0 < 0);
if (neg) argument0 *= -1;

hex = '';
while (argument0) {
  hex = string_char_at(lang, (argument0 & 15) + 1) + hex;
  argument0 = argument0 >> 4;
}

return neg*'-' + hex;

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.