1

I am currently trying to figure out how to make the correct conversion from two's complement hexadecimal to its base 10 equivalent. We were given an assembly language program that adds and subtracts 32-bit integers and need to take the values of the registers and convert them.

Here is what I've attempted, however, my professor says I've made a critical error in my final calculation and I have no clue what.

Here is the register EAX value: FFFC0888

I then converted it from two's complement hexadecimal to hexadecimal: FFFC0888 -> 0003F778

And finally converted the hexadecimal to decimal. 0003F778 = (0 X 16^7) + (0 X 16^6) + (0 X 16^5) + (3 X 16^4) + (15 X 16^3) + (7 X 16^2) + (7 X 16^1) + (8 X 16^0) = 0+0+0+196608+61440+1792+112+8= 259960

My final answer of 259960 is not correct, can someone please help enlighten me as to what I'm doing wrong? Thank you!

1
  • 1
    is it because you failed to mention the answer as -259960 ? Commented May 7, 2015 at 3:11

2 Answers 2

1

(@chathux hints at the answer).

You have a value X==FFFC0888_16. When you converted X to 0003F778 (by taking "twos complement"), you did so because you (should have) thought the X value was "negative" (the sign bit is set). The decimal value you produced 259960 is the correct magnitude, that is abs(X) == 259960_10. But the value of X is negative, so the correct answer is X == -259960_10.

If the value of X==7FFC0888_16, a positive value (sign bit is zero), you should not take the two's complement before you produce the decimal value.

Sign up to request clarification or add additional context in comments.

Comments

1

Everything in your conversion was correct, except that:

0003F778 = -(0 + 0 + 0 + (3 X 16^4) + (15 X 16^3) + (7 X 16^2) + (7 X 16^1) + (8 X 16^0)) 

where 0003F778 is 2s complement integer data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.