Question

In: Computer Science

(a) Convert the decimal numbers, 70 and -26 to binary in the signed 2’s complement system....

(a) Convert the decimal numbers, 70 and -26 to binary in the signed 2’s complement system. Make sure there are enough digits in the results to be able to perform arithmetic operations with these two numbers.

(b) Perform in the signed 2’s complement system, (+70) + (-26)

(c) Perform in the signed 2’s complement system, (-70) - (-26)

(d) Perform in the signed 2’s complement system, (+70) + (+26)

Solutions

Expert Solution

a)
70
Since this is a positive number. we can directly convert this into binary
Divide 70 successively by 2 until the quotient is 0
   > 70/2 = 35, remainder is 0
   > 35/2 = 17, remainder is 1
   > 17/2 = 8, remainder is 1
   > 8/2 = 4, remainder is 0
   > 4/2 = 2, remainder is 0
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1000110
So, 70 of decimal is 1000110 in binary
so, 70 in 2's complement binary is 01000110

-26
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 26 successively by 2 until the quotient is 0
   > 26/2 = 13, remainder is 0
   > 13/2 = 6, remainder is 1
   > 6/2 = 3, remainder is 0
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11010
So, 26 of decimal is 11010 in binary
So, 26 in normal binary is 00011010
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00011010 is flipped to 11100101
Step 3:. Add 1 to above result
11100101 + 1 = 11100110
so, -26 in 2's complement binary is 11100110

b)
Adding 01000110 and 11100110 in binary
    01000110
    11100110
-------------
 (1)00101100
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 00101100

Verification:
---------------
sum = 00101100
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 101100 to decimal
101100
=> 1x2^5+0x2^4+1x2^3+1x2^2+0x2^1+0x2^0
=> 1x32+0x16+1x8+1x4+0x2+0x1
=> 32+0+8+4+0+0
=> 44
Answer: 44
This is correct since we can verify that 70+-26 = 44
So, there was no overflow.

c)
Number: -70
Let's convert this to two's complement binary
-70
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 70 successively by 2 until the quotient is 0
   > 70/2 = 35, remainder is 0
   > 35/2 = 17, remainder is 1
   > 17/2 = 8, remainder is 1
   > 8/2 = 4, remainder is 0
   > 4/2 = 2, remainder is 0
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1000110
So, 70 of decimal is 1000110 in binary
So, 70 in normal binary is 01000110
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   01000110 is flipped to 10111001
Step 3:. Add 1 to above result
10111001 + 1 = 10111010
so, -70 in 2's complement binary is 10111010

Number: 26
Let's convert this to two's complement binary
26
Since this is a positive number. we can directly convert this into binary
Divide 26 successively by 2 until the quotient is 0
   > 26/2 = 13, remainder is 0
   > 13/2 = 6, remainder is 1
   > 6/2 = 3, remainder is 0
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11010
So, 26 of decimal is 11010 in binary
so, 26 in 2's complement binary is 00011010

Adding 10111010 and 00011010 in binary
    10111010
    00011010
-------------
 (0)11010100
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 11010100

Verification:
---------------
sum = 11010100
since left most bit is 1, this number is negative number.
so, follow these steps below to convert this into a decimal value.
I. first flip all the bits. Flip all 0's to 1 and all 1's to 0.
   11010100 is flipped to 00101011
II. Add 1 to above result
00101011 + 1 = 00101100
III. Now convert this result to decimal value
Converting 101100 to decimal
101100
=> 1x2^5+0x2^4+1x2^3+1x2^2+0x2^1+0x2^0
=> 1x32+0x16+1x8+1x4+0x2+0x1
=> 32+0+8+4+0+0
=> 44
Answer: -44
This is correct since we can verify that -70+26 = -44
So, there was no overflow.

d)
Number: 70
Let's convert this to two's complement binary
70
Since this is a positive number. we can directly convert this into binary
Divide 70 successively by 2 until the quotient is 0
   > 70/2 = 35, remainder is 0
   > 35/2 = 17, remainder is 1
   > 17/2 = 8, remainder is 1
   > 8/2 = 4, remainder is 0
   > 4/2 = 2, remainder is 0
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 1000110
So, 70 of decimal is 1000110 in binary
so, 70 in 2's complement binary is 01000110

Number: 26
Let's convert this to two's complement binary
26
Since this is a positive number. we can directly convert this into binary
Divide 26 successively by 2 until the quotient is 0
   > 26/2 = 13, remainder is 0
   > 13/2 = 6, remainder is 1
   > 6/2 = 3, remainder is 0
   > 3/2 = 1, remainder is 1
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 11010
So, 26 of decimal is 11010 in binary
so, 26 in 2's complement binary is 00011010

Adding 01000110 and 00011010 in binary
    01000110
    00011010
-------------
 (0)01100000
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 01100000

Verification:
---------------
sum = 01100000
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 1100000 to decimal
1100000
=> 1x2^6+1x2^5+0x2^4+0x2^3+0x2^2+0x2^1+0x2^0
=> 1x64+1x32+0x16+0x8+0x4+0x2+0x1
=> 64+32+0+0+0+0+0
=> 96
Answer: 96
This is correct since we can verify that 70+26 = 96
So, there was no overflow.

Related Solutions

Convert decimal +47 and +31 to binary, using the signed-2’s-complement representation and enough digits to accommodate...
Convert decimal +47 and +31 to binary, using the signed-2’s-complement representation and enough digits to accommodate the numbers. Then perform the binary equivalent of (+31)+(-47), (-31)+(+47), and (-31)+(-47). Convert the answers back to decimal and verify that they are correct.
Add or subtract the following 2’s complement form signed numbers, then convert the entire problem to...
Add or subtract the following 2’s complement form signed numbers, then convert the entire problem to decimal and confirm: 110110 + 111000 001100 – 011100
i need to convert decimal to twos complement binary and then add the binary digits but...
i need to convert decimal to twos complement binary and then add the binary digits but I am unable to do it. I am only allowed to use string, can anyone help me out please. i need the code urgently. #include #include #include #include using namespace std; string reverse(string s) { string x = ""; for (long i = s.length() - 1; i >= 0; i--) { x += s[i]; } return x; } string twosComplementStringsAddition(string A, string B) {...
The standard method of representing negative numbers in the binary system is with 2's complement notation....
The standard method of representing negative numbers in the binary system is with 2's complement notation. What are the advantages and disadvantages of using this method to represent negative numbers?
Design a 9’s complement of a Binary Coded Decimal
Design a 9’s complement of a Binary Coded Decimal
Write a program to convert the input numbers to another number system. 1. Decimal to Binary...
Write a program to convert the input numbers to another number system. 1. Decimal to Binary 2. Binary to Decimal 3. Hexadecimal to Decimal 4. Decimal to Hexadecimal 5. Binary to Hexadecimal 6. Hexadecimal to Binary The user will type in the input number as following: Binary number : up to 8 bits Hexadecimal number: up to 2 bytes Decimal number: Less than 256 As a result, print out the output after the conversion with their input numbers. The program...
Convert these numbers from Decimal to Binary 111: 66: 252 11 20 Convert these numbers from...
Convert these numbers from Decimal to Binary 111: 66: 252 11 20 Convert these numbers from Binary to Decimal 00110110 11111000 00000111 10101010 What is the Default Subnet mask of Class A IPV4 What is the Default Subnet mask of Class B IPV4 What is the Default Subnet mask of Class C IPV4 What is the CIDR notation or / short handwriting of Subnet masks: Class A: /?. Explain the reason Class B: /? Explain the reason Class C: /?...
Part 2: Signed values: Convert each as indicated. 8. Decimal to Hexadecimal (1 byte, one's complement)...
Part 2: Signed values: Convert each as indicated. 8. Decimal to Hexadecimal (1 byte, one's complement)      a. -18      b. -41
Represent (in binary and separately) the decimal signed whole numbers 347 and -347 in each of...
Represent (in binary and separately) the decimal signed whole numbers 347 and -347 in each of the following formats: (a) sign-magnitude. (b) 1's complement (c) 2's complement (d) excess-511 For Parts (a), (b) and (c), use the minimum number of bits necessary; for Part (d), use the same number of bits as in Parts (a), (b) and (c). CAUTION: You will earn NO CREDITS if you simply show the final result and not clearly show working (i.e., intermediate steps). (If...
7 – For the following operations: • write the operands as 4-bit 2's complement binary numbers,...
7 – For the following operations: • write the operands as 4-bit 2's complement binary numbers, • perform the operation shown, • show all work in binary operating on 4-bit numbers, and • identify overflow if necessary. a) 4 + 2 b) 4 – 2 c) 2 – 4 d) 4 + 4
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT