-1

Here is the example (I have converted them to decimal in advance).
A is 01000001000010000000000000000000^2 (in decimal 8.5)
B is 01000000000100000000000000000000^2 (in decimal 2.25)

The ((+A)-(+B)) should be 6.25 in decimal. Normalizing A and B and matching exponents.

A = 1.00010 * 2^3
B = 0.01001 * 2^3

I can subtract this on paper as follows.

1.00010 * 2^3
- 0.01001 * 2^3
'---------------
0.11001 * 2^3

which is 110.01^2 and in decimal is 6.25.

My problem is how does the CPU work this out? I know that CPU will convert B to twos complement and add the negative B. But every time I tried that, I got 6.75 as answer. Can someone show me how does CPU convert B to two complement to get a negative number and then add to A to get 6.25 as answer. Thanks

Sanone
  • 11
  • 2
  • Hello Dan, I would like to see step by step on how thr cpu will convert B to twos complement and add the negative B to A. by seeng step by step will help me understand many things I am having difficulties with. Thanks – Sanone Jan 04 '17 at 18:37
  • i think my question is specific, it asked "how does the cpu subtract number after converting the number to twos complement". I could do this using pencil and paper but I dont know how the cpu does. i specifically has to show on an assignment how it is being done by the cpu. thanks, no disrespect – Sanone Jan 04 '17 at 18:54
  • How the CPU does this depends on the architecture, e.g. are the special cases with sNaN, qNaN and infinity handled first and then the result is calculated or does the CPU handle both cases in parallel and decides in a later stage what to do. CPU designers use some tricks to do this fast or to save same space on the die. Of course there is some naive way how to calculate a subtraction. – fsasm Jan 04 '17 at 22:33

1 Answers1

0

I have found the answer myself. Twos complement work here as well. Convert B to a negative value using twos complement (flip bits and add 1 bit) and then add the negative to A. But the fractional part with the exponent must be calculated first. Thanks

Sanone
  • 11
  • 2