julie_mcmanus
11 years agoOccasional Contributor
Converting data types
I'm trying to convert an integer to a hex string in Jscript.
Say my value is newdata = -100000,
using the code: var hexString = newdata.toString(16);
it returns the value
-186A0
which is 100000 with the - appended at the front. What I want is FFFE7960
Now in the watch list, when I edit the value for 'newdata' to be Hex, the watch list does display 0xFFFE7960 which is what I'm after but I can't figure how to do this conversion in code.
Say my value is newdata = -100000,
using the code: var hexString = newdata.toString(16);
it returns the value
-186A0
which is 100000 with the - appended at the front. What I want is FFFE7960
Now in the watch list, when I edit the value for 'newdata' to be Hex, the watch list does display 0xFFFE7960 which is what I'm after but I can't figure how to do this conversion in code.
((-10000)>>>0).toString(16)
A smarter person that me answered this question on Stack Overflow! http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript
Look for the 'two's complement hexadecimal representation of a negative number' reply on the page above.