subtraction - Hex Twos Complement Arithmetic -


i'm trying following problem:

 e8b2035d -fb60528d ---------- 

in which, integers represented hex representations of 32-bit two's compliment binary numbers. best approach solve problem, , detect overflow?

subtraction becomes addition when use two's complement. take complement of second number, add them:

as know, two's complement of number starts out turning every 1 0 , vice versa (handy rule of thumb: 15 - number, f -> 0, e -> 1, d -> 2, etc):

fb60528d --> 049fad72 

then add 1 number (in case, 2 + 1 = 3, , there no carry):

049fad73 -- two's complement of fb60528d 

now add numbers, using conventional rules of addition:

e8b2035d 049fad73 + ----------  d + 3 = 10 : write 0, carry 1 1 + 5 + 7  : write d, carry 0 3 + d = 10 : write 0, carry 1 1 + 0 +  : write b, carry 0 2 + f      : write 1, carry 1  1 + b + 9  : write 5, carry 1 1 + 8 + 4  : write d, carry 0 e + 0      : write e 

the final result (still in two's complement) is

ed51b0d0 

you detect overflow if last calculation resulted in carry (a number > f).


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -