Convert decimal HRESULT to hex

HRESULTs are unsigned integers that use the high bit to indicate general success or failure. Javascript converts these into signed integers when using ActiveX objects, so you get error codes like -1072885327 that can’t be easily looked up. Because this code is an error it has the high bit set, and Javascript has converted it to a signed integer.

To convert in JS you can add 0x100000000 to the number (if it’s negative) and then use toString(16) to convert to hex.

function conv(x) { return '0x' + ((x < 0) ? x + 0x100000000 : x).toString(16); }

Here is a form that will do the same thing:



Comments

    Leave a comment