Skip to content

Instantly share code, notes, and snippets.

@DragoniteSpam
Last active December 21, 2020 22:46
Show Gist options
  • Save DragoniteSpam/699de4591ebd7d1715f9baa8f6b341e1 to your computer and use it in GitHub Desktop.
Save DragoniteSpam/699de4591ebd7d1715f9baa8f6b341e1 to your computer and use it in GitHub Desktop.
The opposite of hex().
function string_hex(value, padding) {
if (padding == undefined) padding = 0;
var s = sign(value);
var v = abs(value);
var output = "";
while (v > 0) {
var c = v & 0xf;
output = chr(c + ((c < 10) ? 48 : 55)) + output;
v = v >> 4;
}
if (string_length(output) == 0) output = "0";
return ((s < 0) ? "-" : "") + string_pad(output, "0", padding);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment