Table of Contents

At the lowest abstraction level, computer hardware consists of electronic circuits operating on binary digits (bits). To perform mathematical computations, digital systems must encode both non-negative integers and negative quantities, as well as real numbers with fractional components.

In this note, we develop a deep conceptual foundation for positional number systems, radix complements, 1’s and 2’s complement representations, signed arithmetic, hardware overflow detection, and the IEEE 754 floating-point standard.


1. Number Systems & Radix Complements

1.1 Positional Number Systems

In a positional number system of base (or radix) , a number represents the magnitude: Common bases used in computer computer design are Binary (), Octal (), Decimal (), and Hexadecimal ().


1.2 Radix () and Diminished Radix () Complements

Complements simplify subtraction by converting subtractive logic into additive logic. For an -digit integer in base :

  1. Diminished Radix Complement ( Complement):

    • For Binary (): 1’s Complement . In binary, subtracting a digit from () is equivalent to a bitwise NOT operation.
  2. Radix Complement ( Complement):

    • For Binary (): 2’s Complement .

2. Signed Binary Representations

To represent negative numbers in binary using bits, the Most Significant Bit (MSB) is reserved as the Sign Bit (, ).


2.1 Signed Magnitude Representation

In -bit Sign-Magnitude:

  • MSB (): Represents sign ( for , for ).
  • Remaining bits: Represent absolute magnitude.

Drawbacks:

  1. Dual Zero Representation: and . This wastes a bit pattern and requires double testing for zero in ALU logic.
  2. Complex Subtraction Hardware: Adding and requires separate magnitude comparators and subtractor hardware.

2.2 1’s Complement Representation & Its Limitations

In -bit 1’s complement, a negative number is formed by bitwise inverting all bits of .

The Dual Zero Problem

Like Sign-Magnitude, 1’s complement suffers from two representations of zero:

End-Around Carry Requirement

When adding two 1’s complement numbers, if an output carry is generated from the MSB, it must be added back into the Least Significant Bit (LSB) (called end-around carry). This introduces an extra clock cycle/delay in arithmetic circuits.


2.3 2’s Complement Representation (Deep Intuition)

The 2’s complement representation is the universal standard in all modern processors (x86, ARM, RISC-V).

How to Calculate 2’s Complement

To find in 2’s complement:

  1. Invert all bits of ().
  2. Add to the LSB.

TIP

Shortcut for GATE: Scan the binary number from right to left (LSB to MSB). Keep all bits unchanged up to and including the first 1. Invert every bit after that first 1!

  • Example for in 4 bits: .
  • Scanning from right: 0 (keep), 1 (first 1, keep), 1 (invert to 0), 0 (invert to 1) .

The Modular Clock Wheel Intuition (Modulo )

Why does 2’s complement work so perfectly without needing separate subtractor circuits?

Think of an -bit register as a modular clock wheel with positions (ranging from to ).

Placeholder: Modular Number Wheel for 4-bit 2's Complement

Student Image Note: Place an image named twos-complement-wheel.png in the imgs/ directory. Search description: “4 bit 2s complement number wheel diagram showing signed values from +7 down to -8 and binary patterns 0000 to 1111 arranged in a circle”.

In a 4-bit register ( states):

  • If you start at () and move counter-clockwise by 1 step, you land on ().
  • In signed arithmetic, moving 1 step backward from should equal .
  • Therefore, naturally represents !
  • Moving counter-clockwise by 2 steps lands on .
  • Moving counter-clockwise by 6 steps lands on .

Because arithmetic wraps around modulo : Adding the 2’s complement of () is mathematically identical to subtracting ! The ALU can use a standard adder circuit for both addition and subtraction without needing a subtractor!


Key Advantages of 2’s Complement:

  1. Single Unique Zero:
    • .
    • .
    • Zero has only one representation (), eliminating ambiguity!
  2. Extra Negative Value:
    • Because is eliminated, the bit pattern becomes available to represent an extra negative number: .
  3. No End-Around Carry: Any carry out from the MSB during addition is simply ignored!

3. Comparison & Range Matrix

For an -bit register, the range of representable numbers across formats is:

RepresentationNegative RangePositive RangeTotal Distinct ValuesRepresentation of Zero
UnsignedN/ASingle ()
Sign-MagnitudeDual ( and )
1’s ComplementDual ( and )
2’s ComplementSingle ()

Summary Range Table for Common Bit Widths:

Bit Width ()Sign-Magnitude & 1’s Complement Range2’s Complement Range
4 bits
8 bits
16 bits
32 bits[][]

4. 2’s Complement Arithmetic, Sign Extension & Overflow

4.1 Sign Extension Rule

To convert an -bit signed 2’s complement number into an -bit number () without changing its value:

  • Rule: Replicate the MSB (sign bit) of the -bit number into all extended bit positions on the left.

Examples:

  • Extend (4-bit) to 8-bit:
    • MSB is 0 Extend 0s .
  • Extend (4-bit) to 8-bit:
    • MSB is 1 Extend 1s .

4.2 Addition and Subtraction

To subtract :

  1. Compute the 2’s complement of .
  2. Perform binary addition .
  3. Ignore any final carry out of the MSB.

4.3 Overflow Detection ()

An overflow occurs when the result of an arithmetic operation exceeds the representable range of the -bit signed container.

WARNING

Overflow can only occur when:

  1. Adding two positive numbers yields a negative result ().
  2. Adding two negative numbers yields a positive result (). Adding a positive and negative number can NEVER produce an overflow!

Hardware Overflow Condition

Let be the carry going into the MSB position, and be the carry coming out of the MSB position. Overflow flag is given by:

  • If (Result is incorrect).
  • If (Result is correct).

5. IEEE 754 Floating-Point Standard

Real numbers with fractional parts are represented using the IEEE 754 Floating-Point Standard.


5.1 Format Breakdown (Single & Double Precision)

ParameterSingle Precision (32-bit)Double Precision (64-bit)
Sign Bit ()1 bit (Bit 31)1 bit (Bit 63)
Exponent Bits ()8 bits (Bits 30–23)11 bits (Bits 62–52)
Mantissa/Fraction ()23 bits (Bits 22–0)52 bits (Bits 51–0)
Exponent Bias ()127 ()1023 ()
Bias Formula

5.2 Normalized Numbers & Hidden Bit

For a normalized number, the exponent field is neither all 0s nor all 1s ().

  • Hidden 1 Rule: In binary scientific notation, every non-zero normalized number starts with a leading 1. before the binary point (e.g., ). Since this 1. is always present, IEEE 754 omits it from storage to save 1 bit of precision!
  • The 23 mantissa bits store only the fractional part after the radix point.

Example Conversion: Convert to Single-Precision IEEE 754

  1. Sign bit: Negative .
  2. Binary magnitude: .
  3. Mantissa (): (pad to 23 bits).
  4. Biased Exponent ():
  5. 32-bit representation:

5.3 Special Values & Denormalized Numbers

The exponent values and (255 for Single, 2047 for Double) are reserved for special cases:

Exponent Field ()Mantissa Field ()Value RepresentedDescription
Signed Zero (determined by Sign bit )
Denormalized (Subnormal) Numbers (No hidden 1)
AnyNormalized Numbers
Overflow / Infinity
Not a Number (e.g., , )

NOTE

Denormalized numbers allow gradual underflow for values very close to zero by removing the implicit leading .


6. GATE PYQ-Style Solved Questions

Q1) What is the decimal value represented by the 8-bit 2's complement binary pattern 10110100?

Sol -

  1. Examine MSB: MSB = 1, so the number is negative.
  2. To find its magnitude, take 2’s complement of 10110100:
    • Bitwise NOT: 01001011
    • Add 1: 01001011 + 1 = 01001100
  3. Convert 01001100_2 to decimal:
  4. Include negative sign: .


Q2) Two 4-bit signed 2's complement numbers A = 1001 and B = 1011 are added. Determine the result and check if an overflow occurred.

Sol -

  1. Input values:
  2. Perform binary addition: \begin{array}{r@{\quad}l} 1001 \\ +\ 1011 \\ \hline (1)0100 \end{array}
  3. Truncating to 4 bits: Result = .
  4. Check Overflow:
    • Adding two negative numbers () produced a positive result ()!
    • Bitwise carry check: Carry into MSB , Carry out of MSB ? Let’s trace:
      • Bit 0: , carry =
      • Bit 1: , carry =
      • Bit 2: , carry =
      • Bit 3 (MSB): , carry out
    • .


Q3) A single-precision IEEE 754 floating-point variable has the hex representation 0x41400000. Determine its decimal value.

Sol -

  1. Convert Hex to 32-bit Binary:
  2. Parse Fields:
    • Sign (): Bit 31 = 0 Positive ().
    • Exponent (): Bits 30–23 = .
    • Mantissa (): Bits 22–0 = .
  3. Compute Actual Exponent:
  4. Compute Value: