Skip to content

Instantly share code, notes, and snippets.

@fenying
Created January 10, 2018 06:06
Show Gist options
  • Save fenying/b78a8ccf4be6af94daae32cf7dae97a6 to your computer and use it in GitHub Desktop.
Save fenying/b78a8ccf4be6af94daae32cf7dae97a6 to your computer and use it in GitHub Desktop.
Convert a signed integer into a unsigned 32-bit hex integer string.
function to32BitHex(v) {
if (typeof (v) !== 'number' || (Number.isInteger && !Number.isInteger(v))) {
throw new TypeError("Require a number as the argument.");
}
v = 0xFFFFFFFF & v;
if (v < 0) {
return (v >>> 0).toString(16);
}
else {
return v.toString(16);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment