Created
January 10, 2018 06:06
-
-
Save fenying/b78a8ccf4be6af94daae32cf7dae97a6 to your computer and use it in GitHub Desktop.
Convert a signed integer into a unsigned 32-bit hex integer string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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