Skip to main content
1-Visitor
October 21, 2010
Question

Hexadecimal conversion

  • October 21, 2010
  • 2 replies
  • 7514 views
When try to convert negative decimal number to hexadecimal (by changing the radix under Format Menu > Result > Display options).
the result given by Mathcad does not seem to be correct..
For example, when I represent a variable with the value -53 to hexadecimal I am getting -35h..
(I use M14)
Any suggestions?

2 replies

1-Visitor
October 21, 2010

I'm sure its just the way Mathcad displays hexadecimal numbers - -35 is the correct number though.

Mike

1-Visitor
October 21, 2010

Actually, Mathcad converts 53 to hexadecimal and keeps the negative sign as it is..

If I am not wrong equivalent hexadecimal for -53 would be CB..

-Raj

1-Visitor
October 21, 2010

Excel returns

=DEC2HEX(-53)Converts decimal -53 to hexadecimal (FFFFFFFFCA)

Mike

12-Amethyst
October 21, 2010

I haven't used the display format to view results in hex, but sticking a minus sign in front of a hex number may be mathematically OK (arbitrary base and all that), but it doesn't seem useful. I had made a routine(attached) that gives hex strings for both pos and neg numbers, using 2's complement form. Does this help?

Lou

1-Visitor
October 21, 2010

Thanks Lou. It works great..

However, I am wondering whether it is a known limitation of Mathcad or Am I missing something?

-Raj

12-Amethyst
October 22, 2010

Hexadecimal base is like any other, and negative numbers must to have a representation that must to be the same at any base. There are some "specials" bases: 2 (the minimal of the infinite set of possible bases), 10 (whe have 10 thingers), 16 (is easy converting between base 2 and 16). There are also other usual basis: 12 (eggs are sold by dozens!) 24 and 60 (fond it in the clock) 360 (a babilonian's mistake evaluating the year; we now measute angles in this base).

So, what you're missing is the environment of application. Mathcad answer is correct, just because in general engineering all values are needed, not only the complement to 2^16, this is what is Lou's function do. This is correct in the environment of computation, because you must to take the control over the carriage bit when a operation exceed the usual limit for storage, and have not sense take lowest negative integers as results.

Regards. Alvaro.