By the end of this chapter you'll be able to…

  • 1Convert integers and fractions between bases in the correct reading direction
  • 2Group bits for octal and hexadecimal without arithmetic
  • 3Explain why a terminating decimal fraction may not terminate in binary
  • 4Compare sign-magnitude, one's complement and two's complement by range and zeros
  • 5State why two's complement is used universally
  • 6Read a two's complement value using the negative-weight shortcut
  • 7Apply sign extension correctly when widening a signed value
  • 8Generalise complements to any radix
  • 9Distinguish unsigned overflow from signed overflow
  • 10Apply the same-sign operands rule for signed overflow
  • 11Explain why opposite-signed addition can never overflow
  • 12State the width of the product of two n-bit numbers
  • 13Trace Booth's algorithm on a bit pair and explain its efficiency
  • 14Distinguish restoring from non-restoring division
  • 15Assemble an IEEE 754 single-precision representation
  • 16Explain why the leading 1 is implicit
  • 17Explain why the exponent is biased rather than two's complement
  • 18State the meaning of reserved exponent fields
  • 19Explain denormals and gradual underflow
  • 20Compute machine epsilon and explain relative precision
  • 21Explain why floating-point addition is not associative
  • 22Explain catastrophic cancellation
  • 23State the four IEEE rounding modes and why ties go to even
  • 24Explain BCD and its correction rule
  • 25Convert between binary and Gray code and state why Gray code is used
💡
Why this chapter matters in GATE
A bit pattern carries no meaning by itself. The sequence 1111 1111 is 255 as an unsigned integer, minus one in two's complement, minus 127 in sign-magnitude, and something else again as part of a floating-point field. The representation supplies the meaning, and every question in this chapter is really asking what one pattern means under a stated reading. The second principle is that every representation has a finite range, and the questions live at its boundary: overflow, the asymmetry of the two's complement range, and the loss of precision in floating point are all consequences of running out of bits rather than accidents. The method that follows is to fix the representation, compute the range, and check whether the operation stays inside it. The topic also reaches further than its own marks, since it decides how the ALU is built, why floating-point comparisons fail, and what an overflow flag actually detects.

Before you start — revise these

🔗
School number systems
Positional notation and base conversion are assumed; this chapter builds the signed and floating-point readings GATE examines.
🔗
Boolean Algebra & K-maps
Gray code adjacency and bitwise operations are used there, and complement arithmetic is the numeric counterpart of Boolean complementation.

Number Representation & Computer Arithmetic

Digital Logic contributes a steady share of the core-CS marks, and number representation is the part that reaches furthest: it decides how the ALU is built, why floating-point comparisons fail, and what an overflow flag actually detects.

A bit pattern carries no meaning by itself. The sequence 1111 1111 is 255 as an unsigned integer, in two's complement, in sign-magnitude, and something else entirely as part of a floating-point field. The representation supplies the meaning, and every question in this chapter is really asking what one pattern means under a stated reading.

The second principle is that every representation has a finite range, and questions live at the boundary. Overflow, the asymmetry of the two's complement range, and the loss of precision in floating point are all consequences of running out of bits, and none of them are accidents.

So the method is: fix the representation, compute the range, and check whether the operation stays inside it. That single habit answers most of the examinable material.

1. Positional Systems and Base Conversion

In base , the digit at position contributes its value multiplied by , with positions counted rightwards from zero and fractional positions taking negative exponents.

Converting from base to decimal is direct expansion. Converting decimal to base splits into two halves that use opposite operations.

The integer part is converted by repeated division, reading remainders bottom-up. The fractional part is converted by repeated multiplication, reading the integer overflows top-down.

Mixing the two directions is the standard error. The remainders of the integer part come out least significant first, so they are read in reverse; the overflows of the fraction come out most significant first, so they are read in order.

Between binary, octal and hexadecimal, no arithmetic is needed at all. Group bits in threes for octal and in fours for hexadecimal, starting from the binary point and padding outward.

A decimal fraction that terminates need not terminate in binary. One tenth is in binary, repeating forever, which is the root cause of most floating-point surprises.

2. Signed Integer Representations

Three schemes appear, and they differ in how the negative half of the range is encoded.

SchemeNegation ruleRange for bitsZeros
Sign-magnitudeFlip the sign bit to Two
1's complementInvert all bits to Two
2's complementInvert all bits, add 1 to One

Two's complement is used universally because it has a single zero and because subtraction is addition of the negation, so one adder circuit serves both operations. The other two schemes require end-around carry or separate hardware.

The range is asymmetric: for 8 bits it runs from to . The most negative value has no positive counterpart, so negating it overflows and returns itself, which is a favourite examination point.

A useful shortcut for reading a two's complement number: the most significant bit carries weight while all other bits carry their usual positive weights. So 1011 in 4-bit two's complement is .

Sign extension preserves value when widening. Copy the sign bit into every new high-order position: 1011 extends to 1111 1011, both representing . Zero-filling instead would give 251.

The two complement schemes generalise to any base, and the general names are worth knowing because questions sometimes pose them in base 10.

The 's complement of a number in base is minus the number; the 's complement is minus it, which is obtained digit by digit without any borrow.

In binary these are the two's and one's complements. In decimal they are the 10's and 9's complements, so the 9's complement of 462 is 537, obtained by subtracting each digit from 9, and the 10's complement is 538.

The relationship is uniform: the 's complement is always the 's complement plus one, which is exactly the rule used for two's complement in binary.

3. Two's Complement Arithmetic and Overflow

Addition proceeds identically for signed and unsigned operands — the same adder, the same carries. What differs is how overflow is detected.

Unsigned overflow is signalled by a carry out of the most significant bit. Signed overflow is signalled by the carry into the sign position differing from the carry out of it.

An equivalent and more memorable test: signed overflow occurs exactly when two operands of the same sign produce a result of the opposite sign. Adding two positives cannot legitimately give a negative.

It follows that adding numbers of opposite signs can never overflow, because the magnitude of the result is no larger than the larger operand.

Subtraction is performed as , that is, adding the two's complement of . The same overflow rules then apply to the addition that actually takes place.

A carry out is not an error in unsigned arithmetic if the result is being interpreted modulo , which is exactly what happens in address arithmetic. Whether a carry is an overflow depends on the interpretation, not on the hardware.

4. Multiplication and Division

Unsigned multiplication of two -bit numbers produces a -bit product, which is why hardware multipliers write to a double-width register pair.

Booth's algorithm multiplies signed numbers directly in two's complement without converting to magnitudes, and it accelerates operands containing runs of ones.

The mechanism is to recode a run of ones as a subtraction at the start of the run and an addition just past its end, since a block of ones equals minus 1 in that position. A string of eight ones becomes one subtraction and one addition rather than eight additions.

Booth's algorithm inspects a pair of bits — the current bit and the one to its right — and acts on the transition, with a phantom zero appended below the least significant bit to start the process.

Bit pairAction
00Shift only
01Add multiplicand, then shift
10Subtract multiplicand, then shift
11Shift only

Restoring and non-restoring division are the two examined division algorithms. Restoring division subtracts the divisor and, if the result goes negative, adds it back; non-restoring skips the restore and compensates on the next step, trading a conditional add for a fixed number of steps.

5. Floating Point and IEEE 754

Fixed-point representation places the binary point at a fixed position, giving uniform absolute precision but a narrow range. Floating point moves the point, trading uniform precision for enormous range.

A floating-point number is stored as a sign, a biased exponent and a fraction:

The leading 1 is not stored. Normalisation guarantees exactly one non-zero digit before the point in binary, and since that digit can only be 1, it is implicit and buys one extra bit of precision for free.

FormatSignExponentFractionBias
Single (32-bit)1823127
Double (64-bit)111521023

The exponent is biased rather than stored in two's complement so that the bit patterns compare in the same order as the numbers themselves, which lets integer comparison hardware compare positive floats directly.

Two exponent values are reserved and never used for normalised numbers.

Exponent fieldFractionMeaning
All zerosZeroSigned zero
All zerosNon-zeroDenormal (subnormal)
All onesZeroSigned infinity
All onesNon-zeroNaN

Denormals fill the gap between zero and the smallest normalised number by dropping the implicit leading 1, at the cost of reduced precision — a phenomenon called gradual underflow.

6. Precision, Rounding and Comparison

The exponent controls range and the fraction controls precision, and they trade against each other for a fixed word size. Moving a bit from fraction to exponent widens the range and coarsens the resolution.

Single precision carries 24 significant bits including the implicit one, which is about 7 decimal digits. Double precision carries 53, about 16 decimal digits.

Machine epsilon is the gap between 1.0 and the next representable number, which is for single precision and for double. It is the relative resolution, not an absolute one: the spacing between consecutive floats doubles with every increase in the exponent.

Three consequences are examined directly.

Floating-point addition is not associative. Adding a tiny number to a huge one loses the tiny one entirely, so the order of summation changes the result. This is why summing a large array in different orders gives different answers.

Testing floating-point values for exact equality is unreliable, because values such as 0.1 have no exact binary representation, so 0.1 added three times does not equal 0.3. Comparisons use a tolerance instead.

Subtracting two nearly equal numbers destroys precision, a phenomenon called catastrophic cancellation: the leading significant digits cancel and the result is dominated by whatever rounding error was already present.

IEEE 754 defines four rounding modes, and the default is the one candidates least expect.

ModeBehaviour
Round to nearest, ties to evenDefault
Round toward zeroTruncate
Round toward positive infinityCeiling
Round toward negative infinityFloor

Ties are broken toward the even last bit rather than always upward, because always rounding halves up introduces a systematic upward bias across a long computation, while ties-to-even cancels on average.

7. Codes

Not every binary code is a positional number system, and several exist for reasons other than arithmetic.

Binary Coded Decimal stores each decimal digit in its own group of 4 bits, so 29 becomes 0010 1001. It wastes the six patterns from 1010 to 1111 and requires a correction of adding 6 when a sum exceeds 9, but it makes decimal input and output exact — which is why it survives in financial and display hardware.

Gray code changes exactly one bit between consecutive values, which is what makes it useful for position encoders and for K-map adjacency. A transition that changed several bits at once could be sampled mid-change and read as a wildly wrong value.

Converting binary to Gray code exclusive-ORs each bit with the bit above it, keeping the most significant bit unchanged. Converting back accumulates the exclusive-OR from the top down.

Excess-3 is a self-complementing code in which the 9's complement of a digit is obtained by inverting the bits, which simplified decimal subtraction in early hardware.

8. Worked Examples

Example 1. What decimal value does the 8-bit pattern 1001 0110 represent in unsigned, sign-magnitude, 1's complement and 2's complement?

Unsigned: expand positionally. .

Sign-magnitude: the leading 1 marks it negative and the remaining bits 001 0110 give , so the value is .

1's complement: negative, so invert all bits to recover the magnitude. 0110 1001 is , so the value is .

2's complement: use the negative-weight shortcut. The leading bit carries , and the rest contribute , giving .

Four different values from one pattern, which is the point of the exercise. Note that the 1's complement and 2's complement answers differ by exactly 1, as they always do for negative values.

Example 2. Add the 8-bit two's complement numbers 0110 1100 and 0101 0011. Does signed overflow occur?

Add the patterns bitwise: .

Now check the signs. Both operands begin with 0, so both are positive: 108 and 83, whose true sum is 191.

The result begins with 1, so it reads as negative in two's complement — specifically .

Two positive operands cannot legitimately produce a negative result, so signed overflow has occurred.

Confirm with the carry rule: the carry into the sign position is 1 while the carry out is 0, and the disagreement is exactly the overflow condition.

Note that as an unsigned addition there is no problem: 108 plus 83 is 191, and 1011 1111 is 191. Whether this is an error depends entirely on the interpretation.

Example 3. Represent in IEEE 754 single precision.

Convert the magnitude to binary. The integer part 6 is 110; the fraction 0.75 is .11 since . So .

Normalise: move the point left two places to get .

The sign bit is 1 because the number is negative.

The exponent field is the true exponent plus the bias: , which is 1000 0001 in 8 bits.

The fraction field is the digits after the implicit leading 1, padded to 23 bits: 1011 followed by nineteen zeros.

Assembled: 1 10000001 10110000000000000000000.

The implicit leading 1 is what makes the fraction field start at 1011 rather than 11011, and forgetting to drop it is the commonest error in this conversion.

Example 4. What is the range of an 8-bit two's complement number, and what happens when the most negative value is negated?

The range is to , that is, to .

Negate , whose pattern is 1000 0000. Invert all bits to get 0111 1111, then add 1 to get 1000 0000.

The result is the same pattern, so negating gives .

This is not a bug in the procedure but a consequence of the asymmetric range: simply does not exist in 8-bit two's complement, so the negation has nowhere to land and overflows.

The asymmetry exists because two's complement has a single zero. With patterns, one is spent on zero, leaving 255 to split between positives and negatives, and the split cannot be even.

Example 5. Multiply by using Booth's algorithm with 4-bit operands.

Represent as the multiplicand and as the multiplier , and append a phantom bit .

Examine the bit pair at each step, act, then arithmetic-shift right.

Step 1: pair is , so subtract , then shift. Subtracting means adding 5.

Step 2: pair is , so shift only.

Step 3: pair is , so add , then shift. Adding .

Step 4: pair is , so shift only.

The product is , correct as an 8-bit two's complement result.

The efficiency point is visible in step 2: the run of ones in the multiplier 11 required only the boundary operations at its two ends, not one addition per one-bit.

Example 6. Why does 0.1 + 0.2 == 0.3 evaluate to false in floating-point arithmetic?

Because none of the three values is exactly representable in binary.

One tenth in binary is , an infinitely repeating expansion, exactly as one third is infinitely repeating in decimal. It must be truncated to fit the 23-bit fraction field.

So the stored value for 0.1 is slightly more than one tenth, and the stored value for 0.2 is likewise inexact.

Their sum is then rounded again to the nearest representable value, and that value happens to differ in the last bit from the stored approximation of 0.3.

Two consequences follow. Floating-point equality should be tested against a tolerance rather than exactly. And because each addition rounds, the operation is not associative: summing a long array left to right and right to left can give different totals, with the difference growing when the magnitudes vary widely.

Summary

A bit pattern means nothing without a stated representation, and one pattern reads as four different values under unsigned, sign-magnitude, 1's complement and two's complement.

Convert integers by repeated division reading upward, and fractions by repeated multiplication reading downward. Group bits in threes for octal and fours for hexadecimal.

Two's complement wins because it has one zero and turns subtraction into addition. Its range is asymmetric, so negating the most negative value overflows.

Sign extension copies the sign bit; zero-filling a negative number changes its value.

Unsigned overflow is a carry out; signed overflow is a disagreement between the carry in and carry out of the sign position, equivalently two same-signed operands producing an opposite-signed result.

Booth's algorithm multiplies two's complement operands directly and collapses runs of ones into two boundary operations.

IEEE 754 stores sign, biased exponent and fraction, with the leading 1 implicit. Single precision uses 8 exponent bits with bias 127 and 23 fraction bits; double uses 11 with bias 1023 and 52.

All-zero and all-one exponents are reserved for zero, denormals, infinity and NaN.

The exponent buys range and the fraction buys precision. Floating-point addition is not associative, exact equality is unreliable, and subtracting nearly equal values destroys significance.

BCD makes decimal exact at the cost of wasted patterns; Gray code changes one bit at a time, which is why it suits encoders and K-map adjacency.

Key formulas & results

Everything to memorise for the exam hall, in one card. Screenshot this for revision.

The organising tool
A BIT PATTERN CARRIES NO MEANING BY ITSELF. THE REPRESENTATION SUPPLIES THE MEANING, AND EVERY QUESTION ASKS WHAT ONE PATTERN MEANS UNDER A STATED READING.
FIX THE REPRESENTATION, COMPUTE THE RANGE, AND CHECK WHETHER THE OPERATION STAYS INSIDE IT. THAT HABIT ANSWERS MOST OF THE EXAMINABLE MATERIAL.
Base conversion directions
THE INTEGER PART IS CONVERTED BY REPEATED DIVISION, READING REMAINDERS BOTTOM-UP. THE FRACTIONAL PART IS CONVERTED BY REPEATED MULTIPLICATION, READING INTEGER OVERFLOWS TOP-DOWN.
MIXING THE TWO DIRECTIONS IS THE STANDARD ERROR. GROUP BITS IN THREES FOR OCTAL AND FOURS FOR HEXADECIMAL, PADDING OUTWARD FROM THE BINARY POINT.
Signed representation ranges
SIGN-MAGNITUDE AND ONE'S COMPLEMENT RUN FROM MINUS (2^(n-1) - 1) TO 2^(n-1) - 1 WITH TWO ZEROS. TWO'S COMPLEMENT RUNS FROM MINUS 2^(n-1) TO 2^(n-1) - 1 WITH ONE ZERO.
FOR 8 BITS THAT IS MINUS 128 TO PLUS 127. THE MOST NEGATIVE VALUE HAS NO POSITIVE COUNTERPART, SO NEGATING IT OVERFLOWS AND RETURNS ITSELF.
Why two's complement wins
IT HAS A SINGLE ZERO, AND SUBTRACTION BECOMES ADDITION OF THE NEGATION, SO ONE ADDER CIRCUIT SERVES BOTH OPERATIONS.
SIGN-MAGNITUDE AND ONE'S COMPLEMENT REQUIRE END-AROUND CARRY OR SEPARATE HARDWARE, AND BOTH WASTE A PATTERN ON A SECOND ZERO.
Reading two's complement
THE MOST SIGNIFICANT BIT CARRIES WEIGHT MINUS 2^(n-1) WHILE ALL OTHER BITS CARRY THEIR USUAL POSITIVE WEIGHTS.
SO 1011 IN 4-BIT TWO'S COMPLEMENT IS MINUS 8 PLUS 2 PLUS 1, WHICH IS MINUS 5. THIS IS FASTER THAN INVERTING AND ADDING ONE.
Sign extension
COPY THE SIGN BIT INTO EVERY NEW HIGH-ORDER POSITION WHEN WIDENING A SIGNED VALUE.
1011 EXTENDS TO 1111 1011, BOTH MINUS 5. ZERO-FILLING INSTEAD WOULD GIVE 251, WHICH IS A DIFFERENT NUMBER ENTIRELY.
Radix complements
THE r'S COMPLEMENT IS r^n MINUS THE NUMBER. THE (r-1)'S COMPLEMENT IS r^n MINUS 1 MINUS IT, OBTAINED DIGIT BY DIGIT WITHOUT ANY BORROW.
THE r'S COMPLEMENT IS ALWAYS THE (r-1)'S COMPLEMENT PLUS ONE. IN DECIMAL, THE 9'S COMPLEMENT OF 462 IS 537 AND THE 10'S COMPLEMENT IS 538.
Overflow detection
UNSIGNED OVERFLOW IS A CARRY OUT OF THE MOST SIGNIFICANT BIT. SIGNED OVERFLOW IS THE CARRY INTO THE SIGN POSITION DIFFERING FROM THE CARRY OUT OF IT.
EQUIVALENTLY, SIGNED OVERFLOW OCCURS EXACTLY WHEN TWO OPERANDS OF THE SAME SIGN PRODUCE A RESULT OF THE OPPOSITE SIGN.
When overflow cannot happen
ADDING NUMBERS OF OPPOSITE SIGNS CAN NEVER OVERFLOW, BECAUSE THE MAGNITUDE OF THE RESULT IS NO LARGER THAN THE LARGER OPERAND.
SUBTRACTION IS PERFORMED AS A PLUS THE COMPLEMENT OF B PLUS ONE, SO THE SAME RULES APPLY TO THE ADDITION THAT ACTUALLY TAKES PLACE.
Multiplication width
MULTIPLYING TWO n-BIT NUMBERS PRODUCES A 2n-BIT PRODUCT.
THIS IS WHY HARDWARE MULTIPLIERS WRITE TO A DOUBLE-WIDTH REGISTER PAIR RATHER THAN A SINGLE DESTINATION REGISTER.
Booth's algorithm
INSPECT THE CURRENT BIT AND THE ONE TO ITS RIGHT, WITH A PHANTOM ZERO BELOW THE LEAST SIGNIFICANT BIT. 01 MEANS ADD THEN SHIFT, 10 MEANS SUBTRACT THEN SHIFT, 00 AND 11 MEAN SHIFT ONLY.
IT MULTIPLIES SIGNED NUMBERS DIRECTLY IN TWO'S COMPLEMENT AND COLLAPSES A RUN OF k ONES INTO TWO BOUNDARY OPERATIONS RATHER THAN k ADDITIONS.
Restoring versus non-restoring division
RESTORING DIVISION SUBTRACTS THE DIVISOR AND ADDS IT BACK IF THE RESULT GOES NEGATIVE. NON-RESTORING SKIPS THE RESTORE AND COMPENSATES ON THE NEXT STEP.
THE TRADE IS A CONDITIONAL ADD FOR A FIXED NUMBER OF STEPS, WHICH SUITS PIPELINED HARDWARE.
IEEE 754 value
V = (MINUS ONE) TO THE SIGN, TIMES 1.M, TIMES 2 TO THE (EXPONENT FIELD MINUS BIAS).
THE LEADING 1 IS NOT STORED. NORMALISATION GUARANTEES EXACTLY ONE NON-ZERO BINARY DIGIT BEFORE THE POINT, AND SINCE IT CAN ONLY BE 1, IT IS IMPLICIT AND BUYS A FREE BIT.
IEEE 754 field widths
SINGLE PRECISION: 1 SIGN BIT, 8 EXPONENT BITS WITH BIAS 127, 23 FRACTION BITS. DOUBLE PRECISION: 1, 11 WITH BIAS 1023, AND 52.
THE EXPONENT IS BIASED RATHER THAN TWO'S COMPLEMENT SO THAT BIT PATTERNS COMPARE IN THE SAME ORDER AS THE NUMBERS, LETTING INTEGER HARDWARE COMPARE POSITIVE FLOATS.
Reserved exponent fields
ALL ZEROS WITH ZERO FRACTION IS SIGNED ZERO. ALL ZEROS WITH NON-ZERO FRACTION IS A DENORMAL. ALL ONES WITH ZERO FRACTION IS SIGNED INFINITY. ALL ONES WITH NON-ZERO FRACTION IS NaN.
DENORMALS FILL THE GAP BETWEEN ZERO AND THE SMALLEST NORMALISED NUMBER BY DROPPING THE IMPLICIT LEADING 1, AT THE COST OF PRECISION. THIS IS GRADUAL UNDERFLOW.
Range versus precision
THE EXPONENT CONTROLS RANGE AND THE FRACTION CONTROLS PRECISION, AND THEY TRADE AGAINST EACH OTHER FOR A FIXED WORD SIZE.
SINGLE PRECISION CARRIES 24 SIGNIFICANT BITS INCLUDING THE IMPLICIT ONE, ABOUT 7 DECIMAL DIGITS. DOUBLE CARRIES 53, ABOUT 16 DECIMAL DIGITS.
Machine epsilon
THE GAP BETWEEN 1.0 AND THE NEXT REPRESENTABLE NUMBER: 2 TO THE MINUS 23 FOR SINGLE PRECISION AND 2 TO THE MINUS 52 FOR DOUBLE.
IT IS A RELATIVE RESOLUTION, NOT AN ABSOLUTE ONE. THE SPACING BETWEEN CONSECUTIVE FLOATS DOUBLES WITH EVERY INCREASE IN THE EXPONENT.
The three floating-point consequences
ADDITION IS NOT ASSOCIATIVE. EXACT EQUALITY TESTING IS UNRELIABLE. SUBTRACTING NEARLY EQUAL NUMBERS DESTROYS PRECISION.
ADDING A TINY NUMBER TO A HUGE ONE LOSES IT ENTIRELY; 0.1 HAS NO EXACT BINARY FORM; AND CANCELLATION LEAVES THE RESULT DOMINATED BY PRE-EXISTING ROUNDING ERROR.
Rounding modes
ROUND TO NEAREST WITH TIES TO EVEN IS THE DEFAULT. THE OTHERS ARE TOWARD ZERO, TOWARD POSITIVE INFINITY, AND TOWARD NEGATIVE INFINITY.
TIES GO TO THE EVEN LAST BIT RATHER THAN ALWAYS UPWARD, BECAUSE ALWAYS ROUNDING HALVES UP INTRODUCES A SYSTEMATIC BIAS ACROSS A LONG COMPUTATION.
Binary Coded Decimal
EACH DECIMAL DIGIT IS STORED IN ITS OWN GROUP OF 4 BITS, SO 29 BECOMES 0010 1001. A SUM EXCEEDING 9 REQUIRES A CORRECTION OF ADDING 6.
IT WASTES THE SIX PATTERNS FROM 1010 TO 1111 BUT MAKES DECIMAL INPUT AND OUTPUT EXACT, WHICH IS WHY IT SURVIVES IN FINANCIAL AND DISPLAY HARDWARE.
Gray code
EXACTLY ONE BIT CHANGES BETWEEN CONSECUTIVE VALUES. BINARY TO GRAY EXCLUSIVE-ORS EACH BIT WITH THE BIT ABOVE IT, KEEPING THE MOST SIGNIFICANT BIT UNCHANGED.
A TRANSITION CHANGING SEVERAL BITS AT ONCE COULD BE SAMPLED MID-CHANGE AND READ AS A WILDLY WRONG VALUE, WHICH IS WHY ENCODERS AND K-MAPS USE IT.
⚠️

Traps GATE sets — and how to dodge them

These are the exact option-traps and misreads that cost marks under negative marking.

WATCH OUT
Reading base-conversion remainders and overflows in the same direction
Integer remainders come out least significant first and are read upward; fractional overflows come out most significant first and are read downward. Reversing either produces a digit-reversed answer.
WATCH OUT
Assuming a terminating decimal fraction terminates in binary
One tenth is infinitely repeating in binary, exactly as one third is in decimal. Only fractions whose denominator is a power of two terminate, which is the root of almost every floating-point surprise.
WATCH OUT
Treating the two's complement range as symmetric
It runs from minus 2 to the (n-1) up to 2 to the (n-1) minus 1. There are 256 patterns for 8 bits, one is spent on zero, and 255 cannot split evenly, so the negative side has one extra value.
WATCH OUT
Negating the most negative value and expecting a positive result
Inverting and adding one to 1000 0000 returns 1000 0000. Its positive counterpart does not exist in the representation, so the negation overflows and returns the same pattern.
WATCH OUT
Zero-filling when widening a signed value
Sign extension copies the sign bit into the new positions. Zero-filling 1011 to 0000 1011 turns minus 5 into plus 11, and the value is silently wrong rather than flagged.
WATCH OUT
Using a carry out to detect signed overflow
A carry out detects unsigned overflow. Signed overflow is the disagreement between the carry into the sign position and the carry out of it, equivalently two same-signed operands giving an opposite-signed result.
WATCH OUT
Checking for overflow when the operands have opposite signs
It cannot happen. The magnitude of the result is bounded by the larger operand, so the result always fits. Only same-signed addition can escape the range.
WATCH OUT
Treating an unsigned carry out as an error
In modular address arithmetic a carry out is expected and correct, since the result is intended modulo 2 to the n. Whether a carry indicates an error depends on the interpretation, not on the hardware.
WATCH OUT
Storing the leading 1 in an IEEE 754 fraction field
It is implicit. After normalising to 1.1011 times 2 squared, the fraction field starts at 1011, not 11011, and including the leading digit shifts every subsequent bit.
WATCH OUT
Forgetting to add the bias to the exponent
The stored field is the true exponent plus 127 for single precision or 1023 for double. Storing the raw exponent produces a number smaller than the intended one by a factor of two to the bias.
WATCH OUT
Treating an all-ones exponent as a very large number
It is reserved for infinity and NaN. Similarly an all-zeros exponent means zero or a denormal, so the largest normalised exponent field is 254 for single precision, not 255.
WATCH OUT
Treating machine epsilon as an absolute resolution
It is relative. The spacing between consecutive floats doubles with every increase in the exponent, so the absolute gap near a million is far larger than near one.
WATCH OUT
Comparing floating-point values for exact equality
Values such as 0.1 are stored approximately, so 0.1 plus 0.2 does not equal 0.3 exactly. Compare against a tolerance sized to the magnitudes involved.
WATCH OUT
Assuming floating-point addition is associative
Each addition rounds, so summing a long array in different orders gives different totals. Adding a tiny value to a huge one can lose it entirely, which is why summation order matters numerically.
WATCH OUT
Assuming ties always round upward
The IEEE default is round to nearest with ties to even, because always rounding halves upward introduces a systematic upward bias that accumulates across a long computation.
WATCH OUT
Adding BCD digits without the correction
A group of 4 bits can hold values up to 15, but a decimal digit stops at 9. Whenever a digit sum exceeds 9 or produces a carry, 6 must be added to bring the group back into range.

Exam-pattern practice

PYQ-style questions with full solutions. Work through them as a readiness check — mark yourself honestly and get your gap report at the end.

Readiness check

Are you exam-ready for Number Representation & Computer Arithmetic?

9 problems from this chapter. Try each one, reveal the worked solution, mark yourself honestly — get your gap report at the end.

9 questions~6 min

5-minute revision

The whole chapter, distilled. Read this the night before the exam.

  • A bit pattern has no meaning without a representation.
  • Integer conversion divides and reads remainders upward.
  • Fraction conversion multiplies and reads overflows downward.
  • Group bits in threes for octal, fours for hexadecimal.
  • One tenth repeats forever in binary.
  • Two's complement has one zero; the others have two.
  • Two's complement range is minus 2^(n-1) to 2^(n-1) minus 1.
  • The most significant bit carries weight minus 2^(n-1).
  • Sign extension copies the sign bit.
  • Zero-filling a negative value changes it.
  • The r's complement is the (r-1)'s complement plus one.
  • Subtraction is addition of the two's complement.
  • Unsigned overflow is a carry out.
  • Signed overflow is carry-in differing from carry-out at the sign bit.
  • Same-signed operands giving an opposite-signed result is overflow.
  • Opposite-signed addition never overflows.
  • Negating the most negative value returns itself.
  • An n-bit by n-bit product needs 2n bits.
  • Booth's algorithm acts on bit-pair transitions.
  • 01 adds, 10 subtracts, 00 and 11 shift only.
  • Booth collapses a run of ones into two operations.
  • Booth's worst case is an alternating bit pattern.
  • Restoring division adds the divisor back on a negative result.
  • Non-restoring division compensates on the next step.
  • IEEE single is 1 sign, 8 exponent, 23 fraction, bias 127.
  • IEEE double is 1, 11, 52, bias 1023.
  • The leading 1 is implicit and not stored.
  • The exponent is biased so patterns compare in numeric order.
  • All-zero exponent means zero or a denormal.
  • All-one exponent means infinity or NaN.
  • Denormals give gradual underflow at reduced precision.
  • The exponent buys range; the fraction buys precision.
  • Single carries about 7 decimal digits, double about 16.
  • Machine epsilon is 2 to the minus 23 for single.
  • Float spacing doubles with each exponent increase.
  • Floating-point addition is not associative.
  • Exact float equality testing is unreliable.
  • Cancellation destroys significance.
  • The default rounding mode is nearest, ties to even.
  • BCD stores one decimal digit per 4 bits.
  • BCD sums exceeding 9 need a correction of plus 6.
  • Gray code changes exactly one bit per step.
  • Binary to Gray XORs each bit with the one above.

GATE question blueprint

How this topic is asked, tier by tier — so you can prep to the pattern.

Typical weightage: Digital Logic contributes roughly 6-8 of the 72 core-CS marks; number representation and arithmetic supply 2-3 of those across 1-2 questions

Question styleMarks eachTypical countWhat it tests
Base conversion1~1Integer and fractional conversion directions and hexadecimal grouping
Signed representations1~1Ranges, zeros and reading one pattern under several schemes
Overflow2~1Distinguishing signed from unsigned overflow and applying the sign rule
Booth's algorithm2~1Bit-pair recoding, operation counts and the worst case
IEEE 7542~1Field widths, bias, the implicit leading 1 and reserved exponents
Floating-point precision2~1Machine epsilon, non-associativity, cancellation and rounding modes
Gray code and BCD1~1Conversion procedures and why each code exists

Exam-hall strategy

Battle-tested tips from mentors and toppers for this topic under the sectional clock.

  1. Fix the representation before computing anything; the same pattern has several values.
  2. Use the negative-weight shortcut to read two's complement rather than inverting and adding.
  3. Check overflow by the sign rule: same-signed operands, opposite-signed result.
  4. For IEEE conversions, normalise first, then add the bias, then drop the leading 1.
  5. Remember that all-zero and all-one exponent fields are reserved.
  6. Verify an IEEE answer by converting back in the other direction.
  7. Digital logic is frequently set as NAT, which carries no negative marking, so never leave one blank.
  8. For 1-mark and 2-mark MCQs, negative marking is -1/3 and -2/3, so guess only after eliminating an option.
  9. GATE gives a single freely-navigable 180-minute window, so flag a long Booth or division trace and return to it.

Beyond the exam

Where this skill shows up in the job you're competing for — and in life.

Debugging an integer overflow

Knowing that a same-signed addition producing an opposite sign is the overflow condition is what turns a mysterious negative total into a diagnosed width problem.

Choosing a monetary data type

The fact that one tenth has no exact binary form is why financial systems store amounts in integer minor units or in decimal types rather than in floats.

Summing sensor data accurately

The non-associativity of floating-point addition is why large accumulations are done in ascending magnitude order or with compensated summation.

Reading a rotary position encoder

Gray code is used because only one bit changes per step, so a reading taken mid-transition is never a wildly wrong position.

Where else this topic is tested

Prepare once, score in every exam that asks it.

GATE EC and EEHigh overlap — number systems, two's complement and codes are examined identically, with less emphasis on IEEE 754
UGC NET Computer ScienceHigh overlap — base conversion, complements and IEEE 754 field widths are examined as direct recall
ISRO / BARC / DRDO computer science papersVery high overlap — Booth's algorithm, overflow detection and floating-point representation are recurring MCQ topics

Questions aspirants ask

Pulled from the Q&A community and mentor sessions.

For two reasons that both reduce hardware. The first is that subtraction becomes addition. Since the two's complement of B represents minus B, computing A minus B is just A plus the complement of B plus one, which a single adder handles with an inverter and a carry-in. Sign-magnitude requires comparing magnitudes to decide which way the subtraction goes and what sign the result carries, and one's complement requires an end-around carry, where a carry out of the top must be added back into the bottom. Both need extra logic on the critical path. The second reason is the single zero. Sign-magnitude has plus zero as 0000 0000 and minus zero as 1000 0000; one's complement has 0000 0000 and 1111 1111. Two distinct patterns for the same value means every equality comparison must special-case them, and one of the 256 available patterns is wasted. Two's complement spends that pattern on an extra negative value instead, which is exactly why the range is asymmetric and why negating the most negative value overflows. The asymmetry is not a flaw in the scheme but the price of the single zero, and the price is worth paying because zero comparisons are far more common in real code than negating the extreme value.

The adder is identical in both cases; only the interpretation of the bits differs, so the two conditions are detected differently. Unsigned overflow means the true sum exceeded the largest representable unsigned value, and that shows up as a carry out of the most significant bit. Signed overflow means the true sum fell outside the two's complement range, and that shows up as a disagreement between the carry into the sign position and the carry out of it. The easier form to remember is the sign rule: signed overflow occurs exactly when two operands of the same sign produce a result of the opposite sign. Two positives cannot legitimately sum to a negative, and two negatives cannot sum to a positive. It also follows immediately that adding operands of opposite signs can never overflow, because the result's magnitude is bounded by the larger operand's. A worked contrast makes the independence clear. Adding 1000 0001 and 1111 0000 as 8-bit values produces a carry out and a result of 0111 0001. As unsigned numbers, 129 plus 240 is 369, which exceeds 255, so the carry out correctly flags unsigned overflow. As signed numbers, minus 127 plus minus 16 is minus 143, below minus 128, and the two negatives producing a positive correctly flags signed overflow. Both happen to fire here, but each can fire without the other.

So that the bit patterns of floating-point numbers sort in the same order as the numbers themselves, which lets ordinary integer comparison hardware compare floats. Consider two positive floats. Their sign bits are both 0, and the exponent field occupies the next most significant bits. With a biased representation, a larger true exponent always produces a larger exponent field, so comparing the two 32-bit patterns as if they were unsigned integers gives the correct floating-point ordering, with the fraction field acting as a tiebreaker when the exponents match. That property is why sorting an array of positive floats can reuse an integer comparator, and why the bit layout puts the exponent above the fraction rather than the other way round. Two's complement would break it. A true exponent of minus 1 would be stored as 1111 1111 and an exponent of plus 1 as 0000 0001, so the smaller number would compare as larger. A second, quieter benefit is that the two reserved exponent values fall at the two ends of the biased range, all zeros and all ones, which is a natural place to put zero, denormals, infinity and NaN. The cost is that the stored field must have the bias subtracted before use, and forgetting that subtraction, or subtracting when assembling rather than adding, is the commonest error in IEEE conversion questions.

Because every operation rounds its result to the nearest representable value, and rounding depends on the magnitudes involved. Consider adding a very large number and a very small one. If the small value falls below half the spacing between representable numbers near the large one, the rounded sum is just the large number again and the small value is lost entirely. Group the additions differently, so that many small values are added to each other first, and their accumulated total may be large enough to survive when finally added to the big number. The two orders give different answers. The practical case is summing a long array where the running total grows much larger than the individual elements: adding left to right progressively loses the small elements, while summing in ascending order of magnitude, or splitting into partial sums, preserves far more of them. This is exactly why numerical libraries offer compensated summation algorithms. Two related effects are examined alongside it. Exact equality testing is unreliable because values such as 0.1 have no finite binary expansion, so a computed 0.1 plus 0.2 differs from a stored 0.3 in the last bit. And catastrophic cancellation occurs when two nearly equal numbers are subtracted: the leading significant bits cancel, and what remains is dominated by rounding error already present in the operands, so a result that looks precise may carry almost no correct digits.

It saves arithmetic operations on runs of ones, by exploiting the identity that a block of k consecutive ones equals the next power of two minus one at that position. A naive shift-and-add multiplier performs one addition for every one-bit in the multiplier, so a multiplier of 0111 1110 with six ones costs six additions. Booth's algorithm instead recodes the run as a subtraction at the low end and an addition just past the high end, costing two operations regardless of how long the run is. Mechanically it inspects the current bit and the bit to its right, with a phantom zero appended below the least significant bit, and acts only on transitions: a 10 pair starts a run and subtracts, a 01 pair ends one and adds, while 00 and 11 pairs shift only. A second benefit, independent of speed, is that it handles two's complement operands directly. There is no need to convert negative operands to magnitudes, multiply, and reapply the sign, which is what a naive multiplier requires. The worst case is an alternating pattern such as 0101 0101, where every bit pair is a transition, every step performs an add or subtract, and the algorithm does exactly as much arithmetic as the naive method while carrying extra recoding logic. Modified Booth encoding, which examines three bits at a time, exists precisely to bound that worst case.
Header Logo