Q: 1 The addition of 4-bit, 2’s complement binary numbers 1101 and 0100 results in:
0001 and an overflow
1001 and no overflow
0001 and no overflow
1001 and an overflow
[ Option C ]
There are basically two methods for finding the signed value of a 2’s complement number.
Subtraction Method:
If the Most Significant Bit (MSB) of an n-bit binary number is 1, the number is treated as negative and its signed value is obtained by subtracting 2n from its unsigned decimal value.
Any binary number with MSB = 1 represents a negative value. Direct conversion rule for an n-bit 2’s complement number with MSB = 1:
Signed value = Unsigned value - 2n
In an n-bit 2’s complement system, the total number of possible binary combinations is 2n.
So:
Traditional 2’s Complement Method:
In this, when the MSB is 1, all bits of the number are first inverted to obtain the 1’s complement, and then 1 is added to get the 2’s complement. The resulting binary number is converted into its decimal equivalent, and a negative sign is applied to obtain the signed value.
In this question, two 4-bit 2’s complement binary numbers, 1101 and 0100, are added. In a 4-bit 2’s complement system, numbers with MSB = 1 represent negative values, while numbers with MSB = 0 represent positive values.
The signed range of a 4-bit 2’s complement system is -8 to +7.
1101 (4-bit):
Its unsigned value is 13, and by subtracting 24 = 16, its signed value becomes -3.
0100 (4-bit):
The binary number 0100 has MSB = 0, so it represents a positive number, which is +4.
Now, performing binary addition:
1101 + 0100 = 1 0001 or -3+(+4) = +1 and in binary 0001
Since the system is 4-bit, only the lower 4 bits are stored, giving the result 0001, which represents +1. The carry generated beyond the 4th bit is ignored in signed arithmetic.
To check for overflow, we apply the 2’s complement overflow rule, overflow occurs only when both operands have the same sign and the result has a different sign.
In this case, one operand is negative (-3) and the other is positive (+4). Since the operands have different signs, overflow cannot occur, regardless of the carry.
Q: 2 A CPU has an arithmetic unit that adds bytes and then sets its V, C and Z flag is as follows:
The V-bit is set if arithmetic overflow occurs.
The C-bit is set if a carry-out is generated from the most significant bit during an operation.
The Z-bit is set if the result is zero.
What are the value of V, C and Z flag respectively after the 8-bit bytes 1100 1100 and 1000 1111 are added?
0, 0, 0
1, 1, 0
1, 1, 1
0, 1, 0
[ Option B ]
The two 8-bit bytes are 1100 1100 and 1000 1111
In signed 2’s complement representation, since the MSB is 1, both numbers are negative.
Whenever an 8-bit binary number is given and its Most Significant Bit (MSB) is 1, the number represents a negative value in 2’s complement form. In such cases, the signed decimal value can be obtained directly by subtracting 256 from its unsigned binary value.
Signed value = Unsigned Binary Value − 256
During the binary addition of the two 8-bit numbers 1100 1100 and 1000 1111, the result obtained is 1 0101 1011, which is a 9-bit value. Since the CPU is operating with 8-bit registers, it can store only 8 bits of the result.
1100 1100
+ 1000 1111
-------------
1 0101 1011
FLAG EVALUATION:
Carry Flag (C) is associated with unsigned arithmetic operations. It is set when an addition operation generates a carry out of the most significant bit (MSB). In the given addition, the result contains an extra 9th bit, which indicates that a carry has been generated beyond the 8-bit limit. Since this carry goes out of the MSB, the carry flag is set. Therefore, C = 1.
Zero Flag (Z) is set when the final stored result of an arithmetic operation is zero. This flag depends only on the value of the result and is independent of carry or overflow conditions. In the given case, after the addition, the stored 8-bit result is 0101 1011, which is a non-zero value. Hence, the zero flag is not set, and therefore Z = 0.
Overflow is a condition related to signed arithmetic using 2’s complement representation. It occurs when the result of an addition cannot be represented within the fixed number of bits available. For an 8-bit signed system, the valid range is −128 to +127. If the result goes outside this range, overflow occurs.
Overflow happens only under a specific condition. When both operands have the same sign (both positive or both negative) and the result has a different sign, the arithmetic result becomes incorrect for signed numbers. In such a case, the CPU sets the overflow flag (V) to indicate signed overflow.
If two positive numbers are added and the result becomes negative, overflow has occurred. Similarly, if two negative numbers are added and the result becomes positive, overflow also occurs. If the operands have different signs, overflow never occurs, regardless of the result.
In the given addition, both operands have MSB=1, which means both are negative numbers. However, the final stored result has MSB=0, which means the result is positive. Since two negative numbers have produced a positive result, this indicates signed overflow. Therefore, the overflow flag is set, and V = 1.
Final Result V = 1, C = 1, Z = 0.
Q: 3 Let A = 11111010 and B = 00001010 be two 8 bit 2’s complement numbers. Their product in 2’s complement form is?
11000100
10011100
10100101
11010101
[ Option A ]
Find the signed values of A and B
A = 11111010
We can also find signed value using traditional 2’s complement method as:
11111010 : 1’s Complement : 00000101 = 00000101+1 = 00000110 = -6
B = 00001010
Multiply the signed values : (-6)*10=-60
Finally convert -60 into 8-bit 2’s complement:
+60 = 00111100
1’s complement of 00111100 =11000011
2’s complement : 11000011+1 = 11000100
The 8-bit 2’s complement representation of -60 is 11000100
Q: 4 Which of the following is used by ALU to store the intermediate results?
Stack
Heap
Register
Accumulators
[ Option D ]
The ALU (Arithmetic Logic Unit) uses a special register called the Accumulator to store intermediate results during arithmetic and logical operations. After one operation, the result is kept in the accumulator so it can be used in the next operation.
Q: 5 A computer with a 32-bit word size uses 2’s complement to represent numbers. The range of integers that can be represented by this computer is:
-232 to 232
-231 to 232
-231 to 231-1
-232 to 231
[ Option C ]
In a 2’s complement number system, one bit is reserved for the sign, and the remaining bits represent the magnitude of the number. For an n-bit 2’s complement system, the range of integers that can be represented is from −2n-1 to 2n-1−1.
This happens because the Most Significant Bit (MSB) has a negative weight, while all other bits have positive weights. As a result, there is one extra negative number compared to positive numbers.
Here, the word size is 32 bits, so the range of representable integers is from −231 to 231−1.
Q: 6 When two binary numbers are added, then an overflow will never occur if:
Both number of same sign
The carry into the sign bit position and out of sign bit position are not equal
The carry into the sign bit position and out of sign bit position are equal
The carry into sign bit position is 1
[ Option C ]
In 2’s complement addition, overflow is detected by comparing the carry into and carry out of the sign bit. If both carries are equal, overflow will never occur. If they are different, overflow occurs.
Q: 7 Consider the values A=2.0*1030, B=-2.0*1030, C=1.0. Assume that the floating point numbers are represented with 32 bits. What are the values of X and Y when the following sequence of operations are executed on a computer.
X=A+B
Y=A+C
X=X+C
Y=Y+B
X=1.0, Y=1.0
X=1.0, Y=0.0
X=0.0, Y=1.0
X=0.0, Y=0.0
[ Option B ]
In a 32-bit floating-point system, very large and very small numbers cannot always be represented together accurately because of limited precision.
X=A+B
Here, A=2.0×1030 and B=−2.0×1030.
These two numbers are equal in magnitude and opposite in sign, so they cancel each other. Therefore, X = 0.0.
Y=A+C
Adding a very small number (C=1.0) to a very large number (A) does not change the value of A in 32-bit floating point representation. So, due to rounding, Y ≈ A.
X=X+C
Since, X=0.0, adding C=1.0 gives X=1.0.
Y=Y+B
Now Y≈A and B=-A. Adding them again causes cancellation, resulting in Y=0.0.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.