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.
convert +38 and +17 to binary using the signed 2s complement representation and enough digits to...
convert +38 and +17 to binary using the signed 2s complement representation and enough digits to accomaodate the numbers. Then perform the binary equivalent of (-38) and +17
(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) {...
Please convert decimal value -32760 into 2's complement binary value
Please convert decimal value -32760 into 2's complement binary value
a)The decimal equivalent of the signed 2’s complement 8-bit binary number 11010101B is ______________. b)The decimal...
a)The decimal equivalent of the signed 2’s complement 8-bit binary number 11010101B is ______________. b)The decimal equivalent of the unsigned 8-bit hex number 0B4H is ______________. c)The value of the expression ‘H’ – ‘B’ is less than / equal to / greater than that of the expression ‘L’ – ‘C’. d)If the .data segment contains declarations                         A    BYTE      2 DUP (‘a’), ‘+’ B    BYTE      3 DUP (‘b’), 0 C    BYTE      4 DUP (‘c’), ‘–’ D    BYTE     ...
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
Convert the following hexadecimal representations of 16-bit 2’s complement binary numbers to decimal. a.FCAD b.DEAD c.1111...
Convert the following hexadecimal representations of 16-bit 2’s complement binary numbers to decimal. a.FCAD b.DEAD c.1111 d.8000 e.FACE
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?
1) Convert negative fractional decimal number to 8-bit binary number: – 16.625 (use 2's complement binary...
1) Convert negative fractional decimal number to 8-bit binary number: – 16.625 (use 2's complement binary format) Hint: –17 + 0.375 Given the hint above, the fractional number will be divided into two parts, - Whole number, - Fractional part, must be positive (2) Proof to check that your calculation above is correct
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT