Skip to content
GATEiit

GATE CSE · Digital Logic

Number representation and arithmetic (fixed and floating point)

Number systems and base conversion, signed integers (sign-magnitude, 1's and 2's complement) with ranges and overflow, fixed-point fractions, and IEEE 754 floating point: encoding, decoding, special values and arithmetic.

Before you start

  • Positional notation and powers of 2

    Every conversion and range formula is a sum of digit times base power.

  • Binary logic →

    Complements and carries are bitwise operations on binary digits.

  • Adders in the ALU →

    2's complement lets one adder do both addition and subtraction; overflow is detected from its carries.

This topic comes before: Design of arithmetic and logic unit (ALU), Design of combinational and sequential circuits, Instruction set and addressing modes, IPv4: fragmentation, CIDR notation and network address translation (NAT), Memory management and virtual memory

Concept notes

1. Number systems and base conversion

In base r, the digits dk…d1d0.d−1d−2… (each 0≤di<r) have value ∑di ri.

  • Base r to decimal: expand the sum. (1011.01)2=8+2+1+0.25=11.25.
  • Decimal integer to base r: divide repeatedly by r; the remainders read bottom-up are the digits.
  • Decimal fraction to base r: multiply the fraction by r repeatedly; the integer parts read top-down are the digits. Some fractions never end: 0.1 in binary is 0.000110011… (repeating).
  • Binary to octal / hex: group bits in 3s / 4s from the binary point outwards. (1101 0110)2=(D6)16.

Unknown base questions: write both sides as polynomials in r and solve, then check that every digit is less than r. For example (121)r=(144)8 gives r2+2r+1=100, so (r+1)2=100 and r=9.

With n bits an unsigned integer ranges over 0 to 2n−1.

2. Signed integers: three representations

For n bits, the most significant bit (MSB) acts as the sign in all three.

Representation Negate x by Range Zeros
Sign-magnitude flipping the MSB −(2n−1−1) to 2n−1−1 two (+0, −0)
1's complement flipping all bits −(2n−1−1) to 2n−1−1 two
2's complement flipping all bits, then adding 1 −2n−1 to 2n−1−1 one

For 8 bits, 2's complement covers −128 to 127; the other two cover −127 to 127.

Value of a 2's complement pattern: the MSB has weight −2n−1, the rest are normal. 1111 1010=−128+122=−6. Equivalently, a pattern with MSB 1 means (unsigned value) −2n: (FF9C)16 in 16 bits is 65436−65536=−100.

Sign extension: to widen a 2's complement number, copy the sign bit into the new high bits. 1010 (4-bit, −6) becomes 1111 1010 (8-bit, still −6).

The most negative number −2n−1 has no positive partner: negating it gives itself (an overflow).

3. 2's complement arithmetic and overflow

Addition is plain binary addition; the carry out of the MSB is discarded. Subtraction A−B is A+(Bˉ+1), so one adder handles both.

Overflow means the true result is outside the range. It can happen only when both operands have the same sign, and is detected in either of two equivalent ways:

  1. The two operands have the same sign but the result has the other sign.
  2. The carry into the MSB differs from the carry out of the MSB: V=cn−1⊕cn.

A carry out of the MSB on its own is not overflow in signed arithmetic. For example, in 8 bits (−1)+(−1): 1111 1111+1111 1111=1 1111 1110. Drop the carry: −2, correct. Both carries are 1, so no overflow.

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

For unsigned numbers, by contrast, overflow is exactly the carry out of the MSB.

4. Fixed-point numbers

A fixed-point format puts the binary point at a fixed position. With m integer bits and f fraction bits (often written Qm.f), the stored integer N means N×2−f.

  • Resolution (gap between neighbours) =2−f, the same everywhere.
  • Unsigned range: 0 to 2m−2−f.
  • Signed (2's complement over all m+f bits): −2m−1 to 2m−1−2−f.

Example: 8-bit signed, 4 fraction bits, pattern 1011.0100. As an integer 1011 0100=−76; divide by 24: −4.75.

Fixed-point arithmetic is integer arithmetic plus a scale. Adding two numbers with the same f keeps f. Multiplying gives 2f fraction bits, which must be shifted back.

Fixed point Floating point
Gap between values constant 2−f grows with the magnitude
Range for n bits small very large
Hardware simple, fast needs alignment and normalisation

5. IEEE 754 floating point

A normalised binary float is (−1)S×1.M×2E−bias. The leading 1 is not stored (hidden bit).

Format Sign Exponent Fraction Bias
Single (32-bit) 1 8 23 127
Double (64-bit) 1 11 52 1023

Special exponent fields (single):

  • E=0, M=0: ±0. E=0, M≠0: denormal 0.M×2−126 (no hidden 1; fills the gap near zero).
  • E=255, M=0: ±∞. E=255, M≠0: NaN.

So normal exponents run 1…254, actual exponents −126…127.

Key values (single): smallest positive normal 2−126; smallest positive denormal 2−149; largest finite (2−2−23)×2127. The gap between consecutive floats in [1,2) is 2−23; in [2k,2k+1) it is 2k−23.

Encoding a decimal: convert to binary, normalise to 1.xxx×2e, store E=e+127 and the bits after the point.

Addition: align the smaller exponent to the larger by shifting its significand right, add, renormalise, round. Bits shifted out are lost, so float addition is not associative and 0.1 is not exact.

Sexponent Efraction (mantissa) M18 bits23 bitsbit 3130 ... 2322 ... 0value = (-1)^S × 1.M × 2^(E - 127), for 1 ≤ E ≤ 254E = 0: zero (M = 0) or denormal 0.M × 2^(-126)E = 255: infinity (M = 0) or NaN (M ≠ 0)Double: 1 + 11 + 52 bits, bias 1023
IEEE 754 single precision layout and how each exponent field is read.

Formulas to remember

Unsigned range (n bits)
0 to 2n−1
2's complement range (n bits)
−2n−1 to 2n−1−1
Sign-magnitude / 1's complement range
−(2n−1−1) to 2n−1−1
2's complement negation
−x=xˉ+1
Overflow flagCarry into the MSB XOR carry out of the MSB
V=cn−1⊕cn
Fixed point valuef fraction bits; resolution 2−f
N×2−f
IEEE 754 normalised valueBias 127 (single), 1023 (double)
(−1)S×1.M×2E−bias
IEEE 754 denormal value (single)
(−1)S×0.M×2−126
Largest finite single
(2−2−23)×2127

Common mistakes

  • Treating a carry out of the MSB as signed overflow; overflow is carry-in XOR carry-out of the MSB.
  • Using bias 128 instead of 127 for single precision (or 1024 instead of 1023 for double).
  • Forgetting the hidden 1 when decoding a normalised float, or adding it to a denormal (exponent field 0).
  • Giving the 2's complement range as symmetric; it is −2n−1 to 2n−1−1.
  • Reading fraction conversion remainders in the wrong order: integer part bottom-up, fraction part top-down.
  • Accepting an unknown-base answer without checking that every digit is smaller than the base.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Encode −13.625 in IEEE 754 single precision

numerical

Write −13.625 as a 32-bit IEEE 754 pattern in hexadecimal.

  1. Step 1: Convert 13.625 to binary.

    Try it on paper first.

Example 2: Detecting overflow in 8-bit addition

numerical

Add 100 and 50 as 8-bit 2's complement numbers. What pattern results, and is there overflow?

  1. Step 1: Write the operands in binary.

    Try it on paper first.

Example 3: Find the unknown base

numerical

Find the base r for which (121)r=(144)8.

  1. Step 1: Convert the right side to decimal.

    Try it on paper first.

Example 4: Adding two floats

numerical

Add 1.5 and 0.375 the way a floating-point unit does, and give the single precision hex pattern of the result.

  1. Step 1: Write both in normalised binary.

    Try it on paper first.

Previous year questions

26 official GATE CSE questions on this topic, newest first.

Practise these 26 PYQs →

Topic test

10 questions: up to 4 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 CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.