JavaScript challange: convert -2146828218 to 0x800a0046

In Microsoft JScript file system operations may throw exception with code -2146828218. So there is a challenge for you: write a program that will convert the -2146828218 to hex error number 0x800a0046.

The best solution I've found you can read in comments in two hours.

Comments

Dec To Hex: The Roundabout Way

I came up with this one:

// JScript source code

var engine = new ActiveXObject
("MSScriptControl.ScriptControl")

engine.Language = "VBScript"

print (engine.Eval("hex(-2146828218 )"))

Re: Dec To Hex: The Roundabout Way

Thank you, your solution is interesting. I did not know that it is possible to call VBScript from JavaScript with MSScriptControl.ScriptControl.

Solution

var value = -2146828218;
var errorCode = ((value >> 16 & 0xFFFF) * (1 << 16) + (value & 0xFFFF))