Question

In: Computer Science

Evaluate the following expressions, where two’s complement numbers, A is 11111110 and B is 00000010 and...

Evaluate the following expressions, where two’s complement numbers, A is 11111110 and B is 00000010 and indicate the results. a. A + B b. A – B c. B–A d. –B e. – (-A)

Solutions

Expert Solution

A = 11111110
B = 00000010

A = 11111110
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.
   11111110 is flipped to 00000001
II. Add 1 to above result
00000001 + 1 = 00000010
III. Now convert this result to decimal value
Converting 10 to decimal
10
=> 1x2^1+0x2^0
=> 1x2+0x1
=> 2+0
=> 2
Answer: -2

B = 00000010
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 10 to decimal
10
=> 1x2^1+0x2^0
=> 1x2+0x1
=> 2+0
=> 2
Answer: 2

a)
A + B
Adding 11111110 and 00000010 in binary
    11111110
    00000010
-------------
 (1)00000000
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 00000000
00000000 in decimal is 0
Answer: 0

b)
A – B
convert -00000010 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00000010 is flipped to 11111101
Step 2:. Add 1 to above result
11111101 + 1 = 11111110
Adding 11111110 and 11111110 in binary
    11111110
    11111110
-------------
 (1)11111100
-------------
Sum produces a carry of 1. We can ignore that carry.
So, sum of these numbers in binary is 11111100

sum = 11111100
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.
   11111100 is flipped to 00000011
II. Add 1 to above result
00000011 + 1 = 00000100
III. Now convert this result to decimal value
Converting 100 to decimal
100
=> 1x2^2+0x2^1+0x2^0
=> 1x4+0x2+0x1
=> 4+0+0
=> 4
Answer: -4

c. B–A
convert -11111110 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   11111110 is flipped to 00000001
Step 2:. Add 1 to above result
00000001 + 1 = 00000010
Adding 00000010 and 00000010 in binary
    00000010
    00000010
-------------
 (0)00000100
-------------
Sum does not produces a carry
So, sum of these numbers in binary is 00000100

Verification
---------------
sum = 00000100
since left most bit is 0, this number is positive
so, we can directly convert this into a decimal value
Converting 100 to decimal
100
=> 1x2^2+0x2^1+0x2^0
=> 1x4+0x2+0x1
=> 4+0+0
=> 4
Answer: 4

d)
-B
convert -00000010 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00000010 is flipped to 11111101
Step 2:. Add 1 to above result
11111101 + 1 = 11111110

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.
   11111110 is flipped to 00000001
II. Add 1 to above result
00000001 + 1 = 00000010
III. Now convert this result to decimal value
Converting 10 to decimal
10
=> 1x2^1+0x2^0
=> 1x2+0x1
=> 2+0
=> 2
Answer: -2

e)  -(-A)
A = 11111110 
-A = -11111110 
convert -11111110 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   11111110 is flipped to 00000001
Step 2:. Add 1 to above result
00000001 + 1 = 00000010
-A = 00000010

-(-A) = -00000010
convert -00000010 to two's complement
Step 1: flip all the bits. Flip all 0's to 1 and all 1's to 0.
   00000010 is flipped to 11111101
Step 2:. Add 1 to above result
11111101 + 1 = 11111110
so, -(-A) = 11111110

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.
   11111110 is flipped to 00000001
II. Add 1 to above result
00000001 + 1 = 00000010
III. Now convert this result to decimal value
Converting 10 to decimal
10
=> 1x2^1+0x2^0
=> 1x2+0x1
=> 2+0
=> 2
Answer: -2

Related Solutions

Find the decimal equivalents for the following 8-bit two’s complement numbers. a. 0010 0100 Decimal Equivalent...
Find the decimal equivalents for the following 8-bit two’s complement numbers. a. 0010 0100 Decimal Equivalent ___________ b. 1010 1001 Decimal Equivalent ___________ c. 1100 0011 Decimal Equivalent ___________ d. 0101 0101 Decimal Equivalent ___________
What is two’s complement representation? What is one’s complement representation?
What is two’s complement representation? What is one’s complement representation? What is sign-magnitude representation? What is unsigned representation? What is BCD?
All decimal numbers must be converted to signed two’s complement form before working. Use the least...
All decimal numbers must be converted to signed two’s complement form before working. Use the least number of digits necessary (only using one sign bit) to represent the largest number in a given problem. The smaller number must be represented with the same number of bits. If overflow occurs, indicate that with a note. Show step by step subtraction. 13 - 8 6 - 19 21 - 14
All decimal numbers must be converted to signed two’s complement form before working. Use the least...
All decimal numbers must be converted to signed two’s complement form before working. Use the least number of digits necessary (only using one sign bit) to represent the largest number in a given problem. The smaller number must be represented with the same number of bits. If overflow occurs, indicate that with a note. Show step by step addition. 15 + 6 14 + 18 31 + 5
Solve each of the following problems by translating the values into two’s complement notation (using patterns...
Solve each of the following problems by translating the values into two’s complement notation (using patterns of 5 bits), converting any subtraction problem to an equivalent addition problem, and performing that addition. Check your work by converting your answer to base 10 notation. (Watch out for overflow.) a. 5 + 1 b. 12 – 5 c. 5 – 11 d. 12 + 5 e. 5 – 1
Convert the base-10 number to Two’s Complement. Show your work. (a) −12 (b) −32 (c) −57...
Convert the base-10 number to Two’s Complement. Show your work. (a) −12 (b) −32 (c) −57 (d) −112 (e) −24 (f) −85
Assume that we are executing the following code on a 32-bit machine using two’s complement arithmetic...
Assume that we are executing the following code on a 32-bit machine using two’s complement arithmetic for signed integers. Which of the following will be printed when the following code is executed (circle those printed, and show work; e.g., how the values are stored): #include <stdio.h> int main() { char x = 0xF;                // x = ________ char y = -1;                 // y = ________ unsigned char z = 0xFF;      // z = 11111111        if (x<z)     printf("performed unsigned compare,...
Perform the following calculation in a 6-bit two’s complement system. Show your work. Indicate at the...
Perform the following calculation in a 6-bit two’s complement system. Show your work. Indicate at the end if there will be overflow/underflow or not and why. 1810 – 1010
1. What is the two’s complement of: 00110101 2. Carry out the following calculation using 8-bit...
1. What is the two’s complement of: 00110101 2. Carry out the following calculation using 8-bit signed arithmetic (convert to 8-bit binary sequences) and use two’s complement for the negative number, give the result as both an 8-bit binary sequence and in base 10: 127 – 74. 3. What does shifting a binary sequence to left by 3 places correspond to (from the arithmetic standpoint)
Identify the following numbers using 2’s complement by making suitable assumptions: a. 1710 + 610 b....
Identify the following numbers using 2’s complement by making suitable assumptions: a. 1710 + 610 b. 2110 – 410 c. -1310 - 2010
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT