# 2's Complement Arithmetic

## Main Question or Discussion Point

How do you do this problem?

Sum of +17.5 (Base 10) and -43.25 (Base 10) using 2's complement arithmetic.
Difference of +17.5 (Base 10) and -43.25 (Base 10) using 2's complement arithmetic.

The binary representations must have 12 digits. How the heck do I solve a problem with decimals like this? Thanks for any assistance.

Originally posted by Caldus
How do you do this problem?

Sum of +17.5 (Base 10) and -43.25 (Base 10) using 2's complement arithmetic.
Difference of +17.5 (Base 10) and -43.25 (Base 10) using 2's complement arithmetic.

The binary representations must have 12 digits. How the heck do I solve a problem with decimals like this? Thanks for any assistance.
ok, some quick thoughts....
1) first represent the numbers 17.5 and 43.25 in usual binary format. The integer part can be represented by 6 bits + 1 sign bit, and the fractional part can be represented by 2 bits, so you'll need a total of 9 bits. The remaining 12 - 9 = 3 bits can be put either on the ineger or on the fractional part of the number....
2) transform the 2 binary numbers you've obtained in 2's complement
4) reconvert the result in normal binary form, and then to decimal, see if you've got the correct result

uart
Originally posted by Caldus

The binary representations must have 12 digits. How the heck do I solve a problem with decimals like this? Thanks for any assistance.
Easy, just stick in a (fixed) "decimal" point two digits from the left and then use ordinary two's complement. (like just ingnore the "decimal point" and it will work anyway).

Example (5 bit = xxx.xx)

3.5 = 011.10

-3.5 = 2's_comp(3.5) = 1000.00 - 011.10
= 100.10

Now lets test -3.5 in some computations.

3.5 + (-3.5) =
____011.10 +
____100.10
=(1)000.00 As expected

3.75 + (-3.5) =
____011.11 +
____100.10
=(1)000.01 As expected

2.5 + (-3.5) =
_010.10 +
_100.10
=111.00 This is (-1.00) as expected

Note that 2's_comp(111.00) = 1000.00 - 111.00 = 001.00

Last edited: