Friday, October 22, 2004

Hex to decimal to error text

Just figured out that hex-to-decimal can be very, very easy from the command prompt:

Set /a 0x7a

Next step might be to convert it into an error message:

Net helpmsg 122

This can be done in a one-liner:

Set /a e=0x7a & (net helpmsg %e%)

Note the parenthesis – without, the e environment variable does not exist when net… is parsed by the interpreter. With parenthesis, it is treated like a separate line.

If you get an error number like -2147024891, you have to remove the upper 16 bits before you get the real error number:

set /a "-2147024891 & 0xffff"

Note that the quotes are necessary to treat & like a bit-wise and.

Calc R.I.P.

No comments: