Sub topic 16
GATE-Style Problem Patterns and Shortcuts
Assume you know decimal and binary place value, basic binary addition, powers of two, and exponent rules. This chapter gives a repeatable method for solving number-representation questions quickly. Always identify the format before calculating: the number of bits, signedness, exponent convention, fraction convention, and rounding rule.
First identify the representation
Use the following facts as a compact reference.
| Representation | Main question | Important result |
|---|---|---|
| Unsigned, \(n\) bits | What values fit? | \(0\) to \(2^n-1\) |
| 2's complement, \(n\) bits | What signed range fits? | \(-2^{n-1}\) to \(2^{n-1}-1\) |
| Fixed point with \(f\) fractional bits | What is the resolution? | \(2^{-f}\) |
| IEEE-style float | What do exponent bits mean? | Stored exponent minus bias |
For signed integers, the fastest distinction is the number of zeros. In \(n\)-bit sign-magnitude and 1's complement, the range is
\[ -(2^{n-1}-1)\text{ to }2^{n-1}-1 \]
because both have positive and negative zero. In 2's complement, negative zero does not exist, so the minimum is \(-2^{n-1}\).
Integer and fixed-point shortcuts
For 2's complement addition, discard a carry beyond the most significant bit. Overflow occurs only when two operands with the same sign produce a result with the opposite sign.
Subtraction can be changed into addition:
\[ A-B=A+\text{2's complement}(B) \]
For a fixed-point value with \(I\) integer bits and \(F\) fractional bits, treat the stored bit pattern as an integer and divide by \(2^F\). If the format is signed 2's complement, the stored integer has range
\[ -2^{I+F-1}\text{ to }2^{I+F-1}-1 \]
and the real-value range is obtained by dividing both limits by \(2^F\).
def fixed_value(bits, fractional_bits):
width = len(bits)
raw = int(bits, 2)
if bits[0] == "1": # signed 2's complement
raw -= 1 << width
return raw / (1 << fractional_bits)
print(fixed_value("11101000", 3)) # -3.0Custom floating-point formats
For a format with \(s\) sign bits, \(e\) exponent bits, and \(m\) fraction bits, first determine whether the question uses normalized values only or includes special exponent patterns.
For a normalized value:
\[ (-1)^s(1+\text{fraction})2^{E-\text{bias}} \]
If the exponent uses a bias of \(B\), the unbiased exponent is \(E-B\). For a conventional bias, \(B=2^{e-1}-1\), but never assume this when the question states another bias.
The largest finite normalized value usually uses the largest exponent below the reserved all-ones pattern and a fraction of all ones. The smallest positive normalized value uses the smallest nonzero exponent and fraction zero.
Common GATE traps
- Counting the hidden leading 1 for a normalized float: it is not stored, but it contributes to precision.
- Treating an all-ones exponent as an ordinary exponent in IEEE 754.
- Confusing range with precision. Exponent bits mainly control range; fraction bits control spacing.
- Assuming decimal fractions terminate in binary. A fraction terminates only when its reduced denominator contains no prime factors other than 2.
- Declaring overflow from a carry alone. In 2's complement, inspect operand and result signs.
Exercise
An 8-bit 2's complement computation adds 01111111 and 00000001. Is the result valid?
Show answer
The bit result is 10000000, which has a negative sign even though both operands are positive. Therefore signed overflow occurred; the mathematical result 128 is outside the range -128 to 127.