How do I solve problems with decimals using 2's complement arithmetic?

  • Thread starter Thread starter Caldus
  • Start date Start date
  • Tags Tags
    Arithmetic
Click For Summary
To solve problems with decimals using 2's complement arithmetic, first convert the decimal numbers, +17.5 and -43.25, into binary format, allocating 12 bits total. The integer part can be represented with 6 bits and the fractional part with 2 bits, allowing flexibility in bit allocation. Next, transform these binary representations into 2's complement form. Perform the addition or subtraction as required, and finally convert the result back to decimal to verify accuracy. This method effectively handles decimal calculations within the constraints of 2's complement arithmetic.
Caldus
Messages
106
Reaction score
0
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.
 
Mathematics news on Phys.org
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
 
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 let's 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:
Here is a little puzzle from the book 100 Geometric Games by Pierre Berloquin. The side of a small square is one meter long and the side of a larger square one and a half meters long. One vertex of the large square is at the center of the small square. The side of the large square cuts two sides of the small square into one- third parts and two-thirds parts. What is the area where the squares overlap?

Similar threads

  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
2K