return negative value of hexa decimal value - Typescript

-3

I am trying to store a enum value with a hexadecimal number expecting it to store a negative value. But it always returns positive value. How do i extract the negative value from the stored enum value?

const enum MyErrorCode {
unAuthorizedError = 0x80040226
}

If i do a console print for unAuthorizedError, it gives me 2147746342, but i am expecting to get -2147220954 (Decimal from signed 2's complement). How do i achieve this?

The reason why i needed this is i have a central repository where i stored all the codes in negative numbers and in order to compare that error code in my current scenario i am using the hexa decimal stored in enum and comparing it which is always giving me false given the negative and positive differences.

typescript
hex
asked on Stack Overflow May 19, 2020 by Aditya S

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0