GATE 2026 EC Q.45
What is the complement of ?
- (A)
52
- (B)
53
- (C)
54
- (D)
55
IN THE EC AND IN SYLLABUS
Number systems and codes covers how a digital system stores quantities as bit patterns: positional bases and conversion between them, r's and (r−1)'s complements, unsigned and signed (2's-complement) integers, decimal and unit-distance codes (BCD, excess-3, 2421, Gray), IEEE 754 floating point, and parity-based error detection. Problems on it are short calculations, such as reading a bit pattern as a signed value, deciding whether an addition overflowed, converting Gray to binary or decoding a floating-point word. Each one turns on a convention (which carry, which bias, whether there is a hidden 1), so these notes state every convention explicitly.
5 previous-year questions · 5 solved · 7 practice questions
A base- (radix-) number uses the digits to . Each digit is weighted by according to its position: moving left from the radix point and moving right of it. The common bases are binary (), octal (), decimal () and hexadecimal (, digits – then A–F for –).
Conventions used throughout these notes: a subscript gives the base, e.g. . Bits are written MSB first, so in an -bit word is the MSB and is the LSB.
VALUE OF A POSITIONAL NUMBER
Here is the number of integer digits and the number of fraction digits . Every digit must be smaller than the base.
RANGE OF AN N-DIGIT UNSIGNED INTEGER; DIGITS NEEDED
An -digit base- integer takes distinct values. In bits, . For example, 256 needs 9 bits because . The formula needs ; the value 0 still takes one digit.
Conversion procedures
Base to decimal: expand with the weights and add.
Decimal integer to base : divide by repeatedly. The remainders, read from the LAST to the first, are the digits (the first remainder is the least significant digit).
Decimal fraction to base : multiply the fraction by repeatedly. The integer parts, read from the FIRST to the last, are the digits (the first integer part is the digit just right of the point). Stop when the fraction becomes 0 or you have enough digits.
Binary to octal or hex: group the bits in 3s (octal) or 4s (hex) outward from the binary point, leftward for the integer part and rightward for the fraction. Pad with 0s at the outer ends, then replace each group by its digit.
Octal or hex to binary: replace each digit by its 3-bit or 4-bit group. To go between octal and hex, pass through binary.
Bases that are powers of a common base (2, 8 and 16; or 3 and 9) convert by grouping digits in the same way. Between any other two bases (for example base 5 to base 7), convert through decimal.
WORKED EXAMPLE
Convert to binary, octal and hexadecimal.
Integer part, by repeated division by 2: the remainders for 157 are 1, 0, 1, 1, 1, 0, 0, 1 (LSB first). Reading them from the last one gives .
Fraction part, by repeated multiplication by 2: (1), (0), (1), (1). Reading these from the first one gives .
So .
Octal: group in 3s from the point, which gives , i.e. .
Hex: group in 4s, which gives , i.e. .
Check: and .
Answer:
EXAM TIP
A decimal fraction has a terminating binary expansion if and only if its denominator, in lowest terms, is a power of 2. does not terminate: , with the block 0011 repeating forever after the first 0. Any finite binary format therefore stores 0.1 rounded.
EXAM TIP
Unknown-base problems: expand both sides with their weights, solve, and reject any root that is not an integer larger than every digit that appears. For example, gives , i.e. , so . This is valid because every digit is below 5.
R'S AND (R − 1)'S COMPLEMENTS OF AN N-DIGIT BASE-R NUMBER
is an -digit base- integer (leading 0s count towards ). The 's complement replaces every digit by ; adding 1 to it gives the 's complement. For the 's complement has digits; dropping the extra digit leaves 0. If also has fraction digits, its 's complement is . Examples: the 9's and 10's complements of are and ; the 7's and 8's complements of are and . With these are the 1's and 2's complements.
Unsigned subtraction with complements ( and both written with digits)
With the 's complement: form . If a carry comes out of the leftmost digit (the end carry), then : drop the carry, and what remains is . If there is no end carry, then : the sum is the 's complement of , so take its 's complement and attach a minus sign.
With the 's complement: form . If there is an end carry, add it back into the least significant digit (the end-around carry) to get . If there is none, the answer is minus the 's complement of the sum.
Example: in 5 decimal digits. The 10's complement of is , and . Dropping the end carry leaves .
An -bit unsigned integer is simply the positional value of . Signed integers use the MSB as the sign ( positive, negative), under one of three conventions. All three store positive numbers identically; they differ only for negative numbers.
These notes use 2's complement for signed numbers unless a question says otherwise. denotes the complement (inversion) of bit , and denotes the word with every bit inverted.
VALUE OF AN N-BIT 2'S-COMPLEMENT WORD
The MSB has weight . Equivalently, when the MSB is 1, value (unsigned value) . For example, .
RANGES FOR N BITS
For : unsigned is 0 to 255, 2's complement is to , and the other two are to (each has two codes for zero).
NEGATION (COMPLEMENT) RULES
and the results are read as -bit unsigned values, and the carry out of bit is dropped (the arithmetic is modulo ). So in 2's complement, negating gives back; in 1's complement it gives , the second code for zero. In 2's complement, negating gives back (an overflow), because has no -bit code.
Property ( bits) | Sign-magnitude | 1's complement | 2's complement |
|---|---|---|---|
Negative of | flip the sign bit only | invert every bit: | invert every bit, add 1: |
Range | to | to | to |
Codes for zero | two: and | two: and | one |
Distinct values | |||
in 8 bits | |||
Weight of the MSB | sign only (no weight) | ||
Addition | same signs: add the magnitudes and keep the sign; different signs: subtract the smaller magnitude from the larger and take the sign of the larger | add; a carry out of the MSB is added back into the LSB (end-around carry) | add; the carry out of the MSB is discarded |
Sign extension to more bits | keep the sign bit as the new MSB, fill the new magnitude bits with 0s | copy the MSB into every new bit | copy the MSB into every new bit |
Working rules for 2's complement
Negating by hand: scan from the LSB, copy every bit up to and including the first 1, then invert all the remaining bits. For example, () becomes ().
Reading a negative word: either subtract from its unsigned value, or negate it to get the magnitude.
Sign extension from to bits: copy the MSB into the new bits. So () becomes and () becomes . Padding a negative number with 0s changes its value.
Truncation to fewer bits keeps the value only if every discarded bit equals the new MSB.
Arithmetic shifts: a left shift by one bit multiplies by 2, provided the two most significant bits were equal before the shift (otherwise the result overflows). An arithmetic right shift (the MSB is copied into the vacated bit) divides by 2 and rounds towards : () becomes (), not .
FIXED-POINT VALUE (2'S COMPLEMENT, F FRACTION BITS)
The binary point sits bits from the right. The range is to in uniform steps of . For the same number of bits, floating point gives up this uniform step in exchange for a far wider range.
EXAM TIP
The 2's-complement range is asymmetric: it holds one more negative value than positive ones. The most negative word, e.g. in 8 bits, is its own 2's complement, so cannot be formed in 8 bits. Questions about the minimum number of bits for a negative value turn on this: fits in 8 bits, but needs 9.
With 2's complement, one binary adder serves signed and unsigned numbers alike: add the words, keep bits and discard the carry out of the MSB. Subtraction is done as (invert and set the adder's carry-in to 1).
The -bit result is correct whenever the true result lies within the range. When it does not, the stored bits are wrong and the condition is called overflow. Overflow depends on how the bits are interpreted: one carry pattern can be an unsigned overflow and a correct signed result, or the other way round.
Carry convention used here: stage adds , and the incoming carry , and produces . So is the carry into the MSB stage and is the carry out of it.
SIGNED (2'S-COMPLEMENT) OVERFLOW FLAG
Overflow occurs exactly when the carry into the MSB differs from the carry out of it. This holds for addition and for alike.
OVERFLOW FROM THE SIGN BITS
and are the sign bits of the two words entering the adder, and is the sign bit of the sum. In words: two operands of the same sign produced a sum of the other sign. Adding operands of opposite signs can never overflow. For , use the sign bit of , the word the adder actually receives.
UNSIGNED CARRY AND BORROW
When is computed as , means (no borrow) and means .
WORKED EXAMPLE
In 8-bit 2's-complement arithmetic, compute (a) , (b) , (c) . For each, give the 8-bit result, (carry into the MSB), (carry out of the MSB), and whether signed overflow occurs.
Codes: and . and .
(a) . The lower 7 bits sum to , so . The MSB stage adds , so and . The result reads : two positives gave a negative. The true sum, 150, exceeds 127.
(b) . The lower 7 bits sum to , so . The MSB stage adds , so and . The kept 8 bits read , although the true sum is .
(c) . The lower 7 bits sum to , so . The MSB stage adds , so and . The kept 8 bits are , which is correct; the carry out is simply discarded.
Answer: (a) , overflow. (b) , overflow. (c) , no overflow, even though there is a carry out of the MSB.
EXAM TIP
A carry out of the MSB is not the same thing as overflow. For signed numbers, test (or the sign rule). For unsigned numbers, test alone. A frequent trap is a sum of opposite-sign numbers with : the unsigned sum has overflowed, but the signed result is correct.
EXAM TIP
1's-complement addition: if a carry leaves the MSB, add it back into the LSB (the end-around carry). For in 4 bits: , and adding the end-around carry gives .
A code assigns a bit pattern to each symbol; the whole pattern is not necessarily a positional number. A code is weighted when each bit position carries a fixed weight and a digit's value is the sum of the weights of its 1 bits.
Decimal | BCD (8421) | Excess-3 | Binary | Gray |
|---|---|---|---|---|
0 | 0000 | 0011 | 0000 | 0000 |
1 | 0001 | 0100 | 0001 | 0001 |
2 | 0010 | 0101 | 0010 | 0011 |
3 | 0011 | 0110 | 0011 | 0010 |
4 | 0100 | 0111 | 0100 | 0110 |
5 | 0101 | 1000 | 0101 | 0111 |
6 | 0110 | 1001 | 0110 | 0101 |
7 | 0111 | 1010 | 0111 | 0100 |
8 | 1000 | 1011 | 1000 | 1100 |
9 | 1001 | 1100 | 1001 | 1101 |
10 | 0001 0000 | 0100 0011 | 1010 | 1111 |
11 | 0001 0001 | 0100 0100 | 1011 | 1110 |
12 | 0001 0010 | 0100 0101 | 1100 | 1010 |
13 | 0001 0011 | 0100 0110 | 1101 | 1011 |
14 | 0001 0100 | 0100 0111 | 1110 | 1001 |
15 | 0001 0101 | 0100 1000 | 1111 | 1000 |
BINARY TO GRAY
Equivalently, , where is shifted right by one bit with a 0 entering at the MSB. It takes XOR gates and involves no carries. Example: gives .
GRAY TO BINARY
Work from the MSB down. Each binary bit is the XOR of the Gray bit at that position with the binary bit just found on its left. Equivalently, is the parity of all Gray bits from the MSB down to position .
BCD addition, one decimal digit at a time
Add the two BCD digits, plus any carry from the previous digit, as ordinary 4-bit binary.
If the 4-bit sum exceeds (9), or a carry comes out of the 4-bit group, add (6) to that digit.
Send the carry from the correction (or the original carry) on to the next decimal digit.
The correction condition as logic: , where is the binary carry out of the group and is the 4-bit binary sum. is also the decimal carry passed to the next digit.
WORKED EXAMPLE
Add the decimal numbers 58 and 67 in BCD, showing every correction.
In BCD, and .
Units: (15). This exceeds 9, so add : . The units digit is (5), with a carry of 1.
Tens: (12). This exceeds 9, so add : . The tens digit is (2), with a carry of 1.
Hundreds: the carry gives .
Answer: , which is 125 in BCD.
EXAM TIP
BCD is read digit by digit. in BCD is 49, not 73 (73 is its value read as plain binary). BCD also needs more bits than binary: 8 bits of BCD reach only 99, against 255 in binary.
EXAM TIP
Self-complementing codes (excess-3, 2421) let a 9's-complement circuit be built from inverters alone. Check with excess-3: 2 is , and inverting it gives , which is 7 in excess-3. Indeed . A weighted code can be self-complementing only if its weights add up to 9, because the codes of and between them contain every weight exactly once. The 2421 weights add to 9; the 8421 weights add to 15, so BCD is not self-complementing.
EXAM TIP
Gray code is used wherever several bits would otherwise change at once and a momentary mixed reading would be wrong, such as shaft and position encoders or counters read from another clock domain. The K-map row and column order 00, 01, 11, 10 is the 2-bit Gray code.
A floating-point number stores a sign, an exponent and a significand, like scientific notation in base 2. IEEE 754 single precision (32 bits) holds, from MSB to LSB:
A normalized number has the significand . Its leading 1 is not stored (the hidden bit), which gives 24 bits of precision. The exponent carries a bias of 127, so the true exponent is . The codes and are reserved for zero, denormals, infinity and NaN.
SINGLE PRECISION: NORMALIZED VALUE
, where is the fraction MSB. The true exponent runs from to .
SINGLE PRECISION: DENORMAL (SUBNORMAL) VALUE
There is no hidden 1, and the exponent is fixed at , not . Denormals fill the gap between 0 and the smallest normalized number in equal steps of .
Exponent field | Fraction | Meaning |
|---|---|---|
(the sign bit gives or ) | ||
denormal: | ||
to | any | normalized: |
NaN (not a number), the result of e.g. or |
LARGEST AND SMALLEST POSITIVE SINGLE-PRECISION VALUES
has and all 1s (hex 7F7FFFFF). has , (hex 00800000). has and (hex 00000001). The negative values mirror these with .
SPACING OF NORMALIZED NUMBERS
The gap doubles with each power of 2. Absolute resolution therefore worsens as magnitude grows, while the relative gap between neighbours stays between and . Below the denormals take over, with the fixed gap .
EXPONENT BIAS; DOUBLE PRECISION
is the number of exponent bits: gives 127 and gives 1023. Double precision has 1 sign bit, 11 exponent bits and 52 fraction bits, and its denormals use . A question that defines its own format, with a stated bias or a different significand convention (for example with no hidden bit), overrides these values.
Encoding a decimal number in single precision
Set from the sign.
Convert the magnitude to binary (integer and fraction parts separately).
Normalize to by moving the binary point.
Store as an 8-bit unsigned number.
Store the bits after the point as , left-aligned and padded on the right with 0s to 23 bits. The leading 1 is dropped.
Write the 32 bits as and group them in 4s to read the hex.
WORKED EXAMPLE
Give the IEEE 754 single-precision encoding of in hexadecimal.
, since the number is negative.
. For : (1), (0), (1), so . Hence .
Normalize: , so .
.
followed by 17 zeros (the leading 1 is hidden).
The word is . In groups of 4 it reads .
Answer: C15A0000 in hex.
WORKED EXAMPLE
Decode the single-precision words (a) 3F600000 and (b) 80400000 (hex).
(a) splits into , and .
lies between 1 and 254, so the number is normalized: .
(b) splits into , and .
with means a denormal: no hidden 1, and the exponent is . So .
Reading (b) as a normalized number with exponent would give , which is wrong.
Answer: (a) . (b) , a denormal.
EXAM TIP
Common slips: using a bias of 128 instead of 127; forgetting the hidden 1, or adding a hidden 1 to a denormal; treating the exponent field as 2's complement (it is unsigned and biased); packing right-aligned instead of left-aligned.
EXAM TIP
Floating-point addition can absorb a small operand completely. In single precision, rounds back to (round to nearest, ties to even), because the gap between neighbours at is . For the same reason, floating-point addition is not associative: gives , while gives .
A parity bit makes the number of 1s in the transmitted word even (even parity) or odd (odd parity). The receiver recomputes the parity, and a mismatch reveals an error. A single parity bit detects any odd number of flipped bits and misses any even number. It cannot tell which bit is wrong, so it detects errors but cannot correct them.
PARITY BIT
To check, XOR all received bits; with even parity, a result of 1 flags an error. An XOR tree with inputs needs two-input XOR gates.
MINIMUM DISTANCE OF A CODE
is the smallest number of bit positions in which any two valid code words differ. To correct up to errors and also detect up to errors (), . Single parity has , so it detects 1 error and corrects none.
CHECK BITS FOR A SINGLE-ERROR-CORRECTING HAMMING CODE
is the number of data bits and the number of check bits, and you take the smallest that satisfies the inequality. needs (the (7,4) code) and needs . needs , not 4, because . In the usual layout the check bits sit at positions 1, 2, 4, 8, … (numbered from 1), and the recomputed checks (the syndrome), read as a binary number, give the position of a single flipped bit, with 0 meaning no error. The Hamming code has ; adding one overall parity bit raises it to 4, so the extended code corrects 1 error and detects 2.
EXAM TIP
The even-parity bit of a word is the XOR of its bits, so these questions reduce to counting 1s. has five 1s, so its even-parity bit is 1 and its odd-parity bit is 0.
PREVIOUS-YEAR QUESTIONS
Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.
See these papers in full: GATE ECE 2026 · GATE ECE 2024 · GATE ECE 2020 · GATE IN 2025 · GATE IN 2018
What is the complement of ?
52
53
54
55
The 4-bit signed 2's complement form of is
In a number system of base , the equation has as one of its solutions. The value of is ________.
P, Q, and R are the decimal integers corresponding to the 4-bit binary number 1100 considered in signed magnitude, 1's complement, and 2's complement representations, respectively. The 6-bit 2's complement representation of (P + Q + R) is
110101
110010
111101
111001
The representation of the decimal number in base-2 number system is
PRACTICE
Each option shows two 8-bit 2's-complement operands (MSB first) that are added in an 8-bit adder, keeping 8 bits of the sum. Which of these additions produce signed overflow?
Answer: (A), (C)
A: . The sum reads , and two positives gave a negative: overflow.
B: , which is in range. The sum is (the carry out is discarded): no overflow.
C: . The sum keeps , and two negatives gave a positive: overflow.
D: . The sum is with a carry out of 1, but , so : no overflow. A carry out alone is not overflow.
Which of the following statements are correct?
Excess-3 code is self-complementing: inverting every bit of a digit's code gives the code of its 9's complement.
In IEEE 754 single precision, a word whose exponent field is and whose fraction field is non-zero represents NaN.
A single even-parity bit detects every error in which exactly two bits of the word are flipped.
Sign-extending the 4-bit 2's-complement number to 8 bits gives .
Answer: (A), (B)
A is true. For example, 3 is in excess-3; inverting gives , which is 6 in excess-3, and .
B is true: with is NaN, and with is infinity.
C is false. Two flips leave the number of 1s even, so the parity check passes and the error goes undetected.
D is false. is , and sign extension copies the MSB, giving . The word is .
A single-error-correcting Hamming code protects 11 data bits. The minimum number of check bits needed is ______.
Answer:
The smallest with is needed, with .
: , but , so fails.
: and , so holds.
So , which gives the (15, 11) code.
The 8-bit word (MSB first) is read as a 2's-complement integer and as a sign-magnitude integer . The value of is ______.
Answer:
Unsigned value .
2's complement: the MSB is 1, so .
Sign-magnitude: the sign bit is 1 and the magnitude is , so .
.
The 8-bit Gray-code word (MSB first) corresponds to which binary number?
Answer: (A)
.
Each following bit is : , , , , , , .
Binary . Check: , the given Gray word.
Option B is what you get by wrongly applying the binary-to-Gray rule to the Gray word.
and are IEEE 754 single-precision numbers whose 32-bit encodings, in hexadecimal, are and . The decimal value of is ______.
Answer: (accepted range )
: splits into , , . So .
: splits into , , . So .
.
The 16's complement of the 4-digit hexadecimal number is
Answer: (B)
The 15's complement subtracts every digit from F: , , , , giving .
The 16's complement is the 15's complement plus 1: .
Check: , as requires.
Option A is the 15's complement (the is missing).
OFFICIAL GATE 2027 SYLLABUS WORDING
Copied from the GATE 2027 syllabus; see all 2027 syllabi.
GATE EC
Number Representations: Binary, integer and floating-point- numbers
GATE IN
Basics of number systems
Preparing in Kolkata? IAE Academy's course for GATE ECE or GATE IN.