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

  • Thread starter Caldus
  • Start date
  • Tags
    Arithmetic
In summary, to solve a problem with decimals using 2's complement arithmetic, first represent the numbers in binary format. Then transform them into 2's complement and perform the desired operation. Finally, convert the result back to decimal form to check for accuracy. Remember to use a fixed "decimal" point two digits from the left for easier computation.
  • #1
Caldus
106
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
  • #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
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:

1. What is 2's complement arithmetic?

2's complement arithmetic is a method of representing and performing mathematical operations on signed binary numbers. It is commonly used in computer systems to represent negative numbers, as it allows for efficient addition and subtraction operations.

2. How is a negative number represented in 2's complement?

In 2's complement, a negative number is represented by flipping all the bits of its corresponding positive number and adding 1 to the result. This is known as the two's complement operation.

3. What is the advantage of using 2's complement over other methods of representing negative numbers?

2's complement allows for efficient addition and subtraction operations as the same circuitry can be used for both signed and unsigned numbers. It also avoids the need for a separate negative sign bit, which can save memory space.

4. How is addition performed in 2's complement arithmetic?

In 2's complement, addition is performed by simply adding the two numbers together, including any carry bits, and discarding any overflow bits. If the result is a negative number, the two's complement operation can be applied to obtain the correct representation.

5. Can 2's complement be used for multiplication and division?

Yes, 2's complement can be used for multiplication and division by converting the numbers to their positive counterparts, performing the operation, and then converting back to 2's complement. However, the result may need to be truncated or rounded to fit the desired number of bits.

Similar threads

Replies
3
Views
964
  • Engineering and Comp Sci Homework Help
Replies
1
Views
622
Replies
4
Views
907
Replies
4
Views
2K
  • General Math
Replies
1
Views
1K
Replies
7
Views
1K
Replies
4
Views
1K
  • General Math
Replies
2
Views
1K
Replies
4
Views
386
  • Computing and Technology
Replies
4
Views
743
Back
Top