Question

In: Computer Science

(16%) Convert decimal +47 and +38 to binary, using the signed-2’s-complement representation and enough digits to...

  1. (16%) Convert decimal +47 and +38 to binary, using the signed-2’s-complement representation and enough digits to accommodate the numbers, Then, perform the binary equivalent of (+47)+(-38) and (-47)+(-38) using addition. Convert the answers back to decimal and verify that they are correct.

Solutions

Expert Solution

1)
Number: 47
Let's convert this to two's complement binary
Since this is a positive number. we can directly convert this into binary
Divide 47 successively by 2 until the quotient is 0
   > 47/2 = 23, remainder is 1
   > 23/2 = 11, remainder is 1
   > 11/2 = 5, remainder is 1
   > 5/2 = 2, remainder is 1
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 101111
So, 47 of decimal is 101111 in binary
Adding 2 zeros on left hand side of this number to make this of length 8
so, 47 in 2's complement binary is 00101111

Number: -38
Let's convert this to two's complement binary
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 38 successively by 2 until the quotient is 0
   > 38/2 = 19, remainder is 0
   > 19/2 = 9, remainder is 1
   > 9/2 = 4, remainder is 1
   > 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 100110
So, 38 of decimal is 100110 in binary
Adding 2 zeros on left hand side of this number to make this of length 8
So, 38 in normal binary is 00100110
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00100110 is flipped to 11011001
Step 3:. Add 1 to above result
11011001 + 1 = 11011010
so, -38 in 2's complement binary is 11011010

Adding 00101111 and 11011010 in binary
    00101111
    11011010
-------------
 (1)00001001
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 00001001

Verification:
---------------
sum = 00001001
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
=> 1001
=> 1x2^3+0x2^2+0x2^1+1x2^0
=> 1x8+0x4+0x2+1x1
=> 8+0+0+1
=> 9
Answer: 9
This is correct since we can verify that 47+-38 = 9
So, there was no overflow.

2)
Number: -47
Let's convert this to two's complement binary
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 47 successively by 2 until the quotient is 0
   > 47/2 = 23, remainder is 1
   > 23/2 = 11, remainder is 1
   > 11/2 = 5, remainder is 1
   > 5/2 = 2, remainder is 1
   > 2/2 = 1, remainder is 0
   > 1/2 = 0, remainder is 1
Read remainders from the bottom to top as 101111
So, 47 of decimal is 101111 in binary
Adding 2 zeros on left hand side of this number to make this of length 8
So, 47 in normal binary is 00101111
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00101111 is flipped to 11010000
Step 3:. Add 1 to above result
11010000 + 1 = 11010001
so, -47 in 2's complement binary is 11010001

Number: -38
Let's convert this to two's complement binary
This is negative. so, follow these steps to convert this into a 2's complement binary
Step 1:
Divide 38 successively by 2 until the quotient is 0
   > 38/2 = 19, remainder is 0
   > 19/2 = 9, remainder is 1
   > 9/2 = 4, remainder is 1
   > 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 100110
So, 38 of decimal is 100110 in binary
Adding 2 zeros on left hand side of this number to make this of length 8
So, 38 in normal binary is 00100110
Step 2: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00100110 is flipped to 11011001
Step 3:. Add 1 to above result
11011001 + 1 = 11011010
so, -38 in 2's complement binary is 11011010

Adding 11010001 and 11011010 in binary
    11010001
    11011010
-------------
 (1)10101011
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 10101011

Verification:
---------------
sum = 10101011
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.
   10101011 is flipped to 01010100
II. Add 1 to above result
01010100 + 1 = 01010101
III. Now convert this result to decimal value
=> 1010101
=> 1x2^6+0x2^5+1x2^4+0x2^3+1x2^2+0x2^1+1x2^0
=> 1x64+0x32+1x16+0x8+1x4+0x2+1x1
=> 64+0+16+0+4+0+1
=> 85
Answer: -85
This is correct since we can verify that -47+-38 = -85
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.
(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)
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) {...
Convert the following decimal numbers to 16-bit 2’s complement binary. Display your result in hexadecimal. a.3030...
Convert the following decimal numbers to 16-bit 2’s complement binary. Display your result in hexadecimal. a.3030 b.404 c.5050 d.-5050 e.-20000 Show work with steps
1.convert the following numbers from decimal to binary assuming seven-bit twe's complement binary representation: a)49 b)...
1.convert the following numbers from decimal to binary assuming seven-bit twe's complement binary representation: a)49 b) -27 c)0 d) -64 e) -1 f) -2 g) what is the range for this computer as written in binary and in decimal? 2.convert the following numbers from decimal to binary assuming nine-bit twe's complement binary representation: a)51 b) -29 c) -2 d)0 e) -256 f) -1 g ) what is the range for this computer as written in binary and in decimal?
(6 pts) Convert the data representation given below • Convert 10110111 unsigned binary representation, to decimal...
(6 pts) Convert the data representation given below • Convert 10110111 unsigned binary representation, to decimal representation. • Convert 01100000101110000001010111111000 the binary representation to a hexadecimal representation. • Convert 0xBAAADA55 hexadecimal representation, to a binary representation. 2. (8 pts) Complete the following arithmetic operations in two’s complement representation. What are the values of the carry flag and the overflow flag? (Assume a six-bit system) • 31 + 11 • 13 – 15 • (-2) x (-16) • (-15) ÷ 5
Design a 9’s complement of a Binary Coded Decimal
Design a 9’s complement of a Binary Coded Decimal
1.Convert (FA)16 to decimal 2.Convert (10101110)2 to decimal. 3.Convert (0.10101)2 to decimal.
1.Convert (FA)16 to decimal 2.Convert (10101110)2 to decimal. 3.Convert (0.10101)2 to decimal.
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
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT