Question

Im having trouble understand a portion of my textbook on learning assembly language. Its beginning to introduce all ways to represent data in a computer, and im at the point where it covers signed and unsigned numbers in a computer, where signed numbers are either negative or positive numbers. My book does Two's complement operation in hexadecimal, no conversion to binary at all here, and all I have see on the web is only doing it with binary. My book says that you first express your hex number as unsigned, and then subtract this hex number by 10000 base 16 to get the word length representation (supposedly 100000000 base 16 will get you a double word)(the number you subtract from is, in hex, a 1 followed by the number of 0's in the length of the representation).

After reading that, and trying to understand it, it gives me an example, and examples wants the 2's complement of -76. So it converts it to unsigned, which is 4C, and then subtracts 4C from 10000 (word-length here). So we have:

10000
  -4C
_____

but my book says you cannot subtract C from 0, which is true because C is 12, and you cant take 12 away from 0. So it barrows the 1 on the way left and then leaves FFF. Why FFF? I thought F was 15, not 0. So how do the remaining 0's turn to F?

Now we have:

FFF 10
 -4  C
______

After all this, it says that: 10 base 16 minus C base 16 = 16 base 10 minus 12 base 10 = 4. What? 10 base 16 is fine, but how does it turn into 16? I know C is 12, and you cant do 10 minus 12 without getting a negative number, but why does 10 change to 16? And finally it says F base 16 minus 4 = 15 base 10 - 4 base 10 = 11 base 10 = B base 16 That makes sense, but not the 10 turning into 16. Can someone explain this in terms of hex and what is going on here.

-Dan

This:

________

is just a line

Was it helpful?

Solution

The thing to remember is that you're working in Base 16. So, 10 base 16 expressed in base 10 nomenclature = 1 *16^1 + 0 * 16^0 = 16. C in base 16 is 12 (A=10, B=11, C=12, D=13, E=14, F=15). So 10(base 16) - C = (in Base 10 nomenclature) 16 - 12 = 4 (in both base 16 nomenclature and base 10 nomenclature)

Now, to think about your question with "borrowing", if you had the following base 10 subtraction problem:

 1000
 -  8
 -----
  992

You'd rewrite it as

 99 10 
 -   8
 ------
   992

since 1000 = 9*10^2 + 9 *10^1 + 10 (900 + 90 + 10)

The F's here are just acting the same way the 9's do when you need to borrow for subtraction

In your case, 10000 = 16^4 = FFF 10 = 15*16^3 + 15*16^2 + 15 *16^1 + 16

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top