2's Complement Arithmetic

  • Thread starter Caldus
  • Start date
  • #1
106
0

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.
 

Answers and Replies

  • #2
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
3) add, respectively subtract
4) reconvert the result in normal binary form, and then to decimal, see if you've got the correct result
 
  • #3
uart
Science Advisor
2,776
9
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:

Related Threads on 2's Complement Arithmetic

  • Last Post
Replies
4
Views
4K
  • Last Post
Replies
5
Views
3K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
9
Views
1K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
5
Views
684
  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
8
Views
2K
  • Last Post
Replies
5
Views
514
Top