cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Hexadecimal conversion

Raj_mathcad
1-Newbie

Hexadecimal conversion

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?
8 REPLIES 8
MikeArmstrong
5-Regular Member
(To:Raj_mathcad)

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

Mike

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

MikeArmstrong
5-Regular Member
(To:Raj_mathcad)

Excel returns

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

Mike

My Excel returns FFFFFFCB which is the correct 2's complement value. Adding the result CA and 35 gives FF, which = -1 and is incorrect. Mike, looks like your computer (or Excel) needs a remedial math class :-).

Lou

MikeArmstrong
5-Regular Member
(To:LouP)

Lou,

I have just re-checked my Excel and got FFFFFFFCB.

Mike, looks like your computer (or Excel) needs a remedial math class :-).

Me and my computer

Mike

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

Thanks Lou. It works great..

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

-Raj

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.

Top Tags