Skip to content
GATEiit

GATE EC · Digital Circuits

Binary, integer and floating-point numbers

Number systems and base conversion, signed integers (sign-magnitude, 1's and 2's complement), overflow in 2's complement arithmetic, and IEEE 754 floating-point encoding, range and special values.

Before you start

  • Powers of two

    Every range, weight and exponent in this topic is a power of two; know 20 to 216 by heart.

  • Place value in decimal

    Base conversion is the same place-value idea with weights rk instead of 10k.

This topic comes before: ADCs and DACs, Arithmetic circuits, Boolean algebra, Code converters, Machine instructions and addressing modes, Minimization of functions using Boolean identities and Karnaugh map, Shift-registers

Concept notes

1. Positional number systems and base conversion

In base r, the digit string dn−1…d1d0.d−1d−2… has value ∑kdkrk. GATE uses binary (r=2), octal (r=8), hexadecimal (r=16, digits 0–9, A–F) and decimal.

  • Base r to decimal: multiply each digit by its weight and add. (2A.C)16=2⋅16+10+12/16=42.75.
  • Decimal integer to base r: divide repeatedly by r; the remainders, read bottom to top, are the digits.
  • Decimal fraction to base r: multiply the fraction repeatedly by r; the integer parts, read top to bottom, are the digits. Some fractions (like 0.1) never terminate in binary.
  • Binary to octal / hex: group bits in threes / fours outwards from the binary point, padding with zeros. (1011 0110.1)2=(B6.8)16.

An n-bit unsigned number covers 0 to 2n−1. BCD stores each decimal digit in its own 4-bit group, so (59)10=0101 1001 in BCD; the codes 1010 to 1111 are unused. To check a base question quickly, convert both sides to decimal.

2. Signed integers: three representations

With n bits, the MSB carries the sign in all three schemes, but the negative patterns differ.

Scheme How −x is formed Range Zeros
Sign-magnitude set the MSB to 1 −(2n−1−1) to 2n−1−1 two
1's complement invert every bit −(2n−1−1) to 2n−1−1 two
2's complement invert every bit, add 1 −2n−1 to 2n−1−1 one

2's complement is what hardware uses: one zero, and the same adder works for signed and unsigned numbers. Its MSB has weight −2n−1, so 11101010=−128+64+32+8+2=−22.

A quick way to negate in 2's complement: copy bits from the right up to and including the first 1, then invert the rest. The most negative number −2n−1 (1000…0) has no positive partner in n bits; negating it gives itself.

Sign extension: to widen a 2's complement number, copy the sign bit into the new MSBs (1010→1111 1010, still −6). In 1's complement the same rule holds; in sign-magnitude, insert zeros after the sign bit.

3. 2's complement addition and overflow

Add the bit patterns as unsigned numbers and discard the carry out of the MSB. Subtraction A−B is A+(Bˉ+1).

Overflow happens when the true result is outside −2n−1 to 2n−1−1. Two equivalent tests:

  • Both operands have the same sign and the result has the opposite sign. Adding numbers of opposite signs never overflows.
  • The carry into the MSB differs from the carry out of the MSB: V=Cn⊕Cn−1.

Example in 8 bits: 0110 0100+0011 0010 (100+50) gives 1001 0110, which reads as −106. Carry into the MSB is 1, carry out is 0, so V=1.

Do not confuse the carry flag with overflow. The carry out of the MSB signals unsigned overflow; for signed numbers it is ignored. 1111 0000+1111 0000 (−16+−16) produces a carry out but the result 1110 0000=−32 is correct.

In 1's complement, a carry out of the MSB is added back to the LSB (end-around carry).

4. IEEE 754 floating point

A floating-point number is stored as sign S, biased exponent E and fraction M:

Format S E bits M bits Bias
Single (32-bit) 1 8 23 127
Double (64-bit) 1 11 52 1023

For a normalised number (1≤E≤254 in single precision), value =(−1)S×1.M×2E−127. The leading 1 is implied (the hidden bit), so 23 stored bits give 24 bits of precision.

Special exponent values (single precision):

  • E=0, M=0: ±0.
  • E=0, M≠0: denormal, value (−1)S×0.M×2−126. These fill the gap near zero.
  • E=255, M=0: ±∞.
  • E=255, M≠0: NaN.

Key values: smallest positive normal 2−126; smallest positive denormal 2−149; largest finite (2−2−23)×2127≈3.4×1038.

To encode: write the number in binary, normalise to 1.xxx×2e, store E=e+127 and the bits after the point. To decode: split the hex into bits, read S, E, M and apply the formula. The spacing between neighbouring floats grows with the exponent, so precision is relative, not absolute.

SExponent E (8 bits)Mantissa / fraction M (23 bits)3130232201 bitbiased by 127hidden leading 1 is not storedvalue = (-1)^S x 1.M x 2^(E - 127) for 1 <= E <= 254
IEEE 754 single-precision layout: 1 sign bit, 8 exponent bits, 23 fraction bits

Formulas to remember

Value in base r
N=∑kdk rk
n-bit 2's complement range
−2n−1≤N≤2n−1−1
Sign-magnitude and 1's complement rangeBoth have two zeros.
−(2n−1−1)≤N≤2n−1−1
2's complement value
N=−bn−12n−1+∑k=0n−2bk2k
Negation in 2's complement
−A=Aˉ+1
Overflow flagCarry out of the MSB XOR carry into the MSB.
V=Cn⊕Cn−1
IEEE 754 single, normalisedFor 1≤E≤254.
x=(−1)S×1.M×2E−127
IEEE 754 single, denormalFor E=0, M≠0.
x=(−1)S×0.M×2−126

Common mistakes

  • Using the sign-magnitude range for 2's complement: 2's complement has one extra negative number, −2n−1.
  • Calling a carry out of the MSB an overflow in signed addition; overflow is the carry into the MSB XOR the carry out.
  • Forgetting the hidden 1 when decoding an IEEE 754 normalised number, or adding it to a denormal.
  • Subtracting 128 instead of 127 as the single-precision bias, or 1024 instead of 1023 for double.
  • Grouping bits for hex from the left of an integer instead of from the binary point outwards.
  • Sign-extending a negative 2's complement number with zeros, which changes its value.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Encode a decimal number in IEEE 754 single precision

numerical

Write −13.625 in IEEE 754 single-precision format and give the 32-bit pattern in hexadecimal.

  1. Step 1: Convert the magnitude to binary.

    Try it on paper first.

Example 2: Detect overflow in 8-bit 2's complement addition

numerical

In 8-bit 2's complement, add 5A16 and 3C16. Is there overflow? What would the hardware result read as?

  1. Step 1: Convert both operands to signed decimal.

    Try it on paper first.

Example 3: Decode a hexadecimal float

numerical

A register holds the IEEE 754 single-precision pattern C0A8000016. Find its decimal value.

  1. Step 1: Write out the first 12 bits.

    Try it on paper first.

Example 4: How many bits for a given signed range

conceptual

What is the minimum number of bits needed to store every integer from −200 to +200 in 2's complement, and in sign-magnitude?

  1. Step 1: Find the 2's complement width.

    Try it on paper first.

Previous year questions

3 official GATE EC questions on this topic, newest first.

Topic test

10 questions: up to 3 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE EC syllabus; being checked by a reviewer. Updated 2026-11-28. Spotted a mistake? Use Report an issue on any question, or contact us.