Data representation and computer arithmetic — Unit 1 Notes (Computer Organisation and Architecture)

BCS304 · Unit 1

Data representation and computer arithmetic notes — Unit 1

Free unit-wise study notes on data representation and computer arithmetic for Computer Organisation and Architecture, Semester 3 of B.Tech — Computer Science & Engineering — key concepts, examples, important questions and a revision checklist for semester exams.

How hardware actually computes. Covers Fixed and Floating-Point representations (IEEE 754), and hardware arithmetic algorithms including Booth's Multiplication and Restoring/Non-Restoring Division.

Notebook — 14 pages

Page 1

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

1. Introduction to COA

While Digital Logic Design teaches how to build individual gates and registers, Computer Organisation and Architecture teaches how to connect millions of these registers to form a functioning computer.

1.1 Organisation vs. Architecture

  • Computer Architecture: Refers to the attributes of a system visible to a programmer. It defines the conceptual structure and functional behavior. (e.g., Instruction set, number of bits used for data types, I/O mechanisms, addressing techniques).
  • Computer Organisation: Refers to the operational units and their interconnections that realize the architectural specifications. (e.g., Hardware details transparent to the programmer, such as control signals, interfaces, memory technology used, and the internal design of the ALU).

Analogy: Architecture is the floor plan and features of a house. Organisation is the plumbing, wiring, and brickwork used to build it.

Next — Data Representation

1 of 14

Page 2

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

2. Data Representation

A CPU only understands 1s and 0s. The hardware must have standard ways to interpret these binary strings as integers, fractions, or characters.

2.1 Fixed-Point Representation

The radix point (decimal point) is assumed to be at a fixed position. Usually, it's assumed to be at the far right, making the number an integer.

To represent negative numbers, three formats exist:

  • Sign-Magnitude: The MSB is the sign bit (0=Positive, 1=Negative). The remaining bits are the magnitude. Flaw: Has +0+0 and 0-0. Subtraction requires complex logic.
  • 1's Complement: Negative numbers are formed by flipping all bits. Flaw: Still has +0+0 and 0-0. Requires an 'end-around carry' during addition.
  • 2's Complement: Negative numbers are the 1's complement +1+ 1. This is the universal standard for integers. Only one representation for zero. Subtraction is just addition with the 2's complement.

Next — Floating-Point Representation

2 of 14

Page 3

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

3. Floating-Point Representation

Fixed-point cannot represent very large (103010^{30}) or very small (103010^{-30}) numbers efficiently. Floating-point solves this using scientific notation: N=M×REN = M \times R^E.

A floating-point binary number is split into three fields:

  • Sign (SS): 1 bit (0 for +, 1 for -).
  • Exponent (EE): Determines the position of the radix point. Stored in a 'biased' format.
  • Mantissa / Significand (MM): The precision bits of the number.

3.1 Normalization

To ensure a unique representation, numbers are normalized so the most significant bit of the mantissa is non-zero. In binary, the leading bit is ALWAYS a 1 (e.g., 1.0110×251.0110 \times 2^5). Since it's always 1, IEEE standards don't even store it (saving 1 bit of memory). This is the Hidden Bit.

Next — IEEE 754 Standard

3 of 14

Page 4

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

4. IEEE 754 Standard

The universal hardware standard for floating-point math.

4.1 Single Precision (32-bit)

  • Sign: 1 bit (Bit 31)
  • Biased Exponent: 8 bits (Bits 30-23). Bias = 127.
  • Fraction (Mantissa): 23 bits (Bits 22-0).

Value =(1)S×(1.Fraction)×2(Exponent127)= (-1)^S \times (1.\text{Fraction}) \times 2^{(\text{Exponent} - 127)}

4.2 Double Precision (64-bit)

  • Sign: 1 bit (Bit 63)
  • Biased Exponent: 11 bits (Bits 62-52). Bias = 1023.
  • Fraction (Mantissa): 52 bits (Bits 51-0).

Why use Biased Exponents? It allows exponents to be strictly positive integers (ranging from 1 to 254 in single precision), which means a simple integer comparator hardware circuit can compare floating-point numbers quickly.

Next — Hardware Addition & Subtraction

4 of 14

Page 5

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

5. Addition & Subtraction Hardware

Addition and Subtraction of 2's complement integers are executed by the same hardware: a Parallel Adder.

5.1 The Hardware Implementation

Consider registers A and B feeding into an nn-bit adder. We introduce an add/subtract control wire called MM.

  • The bits of register B are passed through XOR gates with MM.
  • MM is also connected to the Carry-In (C0C_0) of the adder.
  • When M=0M=0 (Add): B0=BB \oplus 0 = B. C0=0C_0 = 0. The adder computes A+BA + B.
  • When M=1M=1 (Subtract): B1=BB \oplus 1 = B' (1's complement). C0=1C_0 = 1. The adder computes A+B+1A + B' + 1, which is ABA - B.

5.2 Overflow Detection

An overflow occurs when the sum of two nn-bit numbers requires n+1n+1 bits. In 2's complement, an overflow happens if adding two positive numbers yields a negative result, or adding two negative numbers yields a positive result.

Hardware detection: V=Cn1CnV = C_{n-1} \oplus C_n. If the carry INTO the sign bit differs from the carry OUT OF the sign bit, an overflow has occurred (V=1V=1).

Next — Hardware Multiplication (Unsigned)

5 of 14

Page 6

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

6. Hardware Multiplication (Unsigned)

Multiplication is inherently a process of repeated addition and shifting.

6.1 Shift-and-Add Algorithm

To multiply two nn-bit unsigned integers (Multiplicand MM, Multiplier QQ), we need a 2n2n-bit register to hold the product. We use three registers: AA (initially 0), QQ (holds multiplier), and MM (holds multiplicand).

  • 1. Check the LSB of the multiplier, Q0Q_0.
  • 2. If Q0=1Q_0 = 1, add the Multiplicand MM to AA. (AA+MA \leftarrow A + M).
  • 3. If Q0=0Q_0 = 0, do nothing.
  • 4. Shift the combined registers AA and QQ to the RIGHT by 1 bit. (The LSB of AA shifts into the MSB of QQ. Q0Q_0 drops off).
  • 5. Repeat nn times.

The final product is the combined 2n2n-bit value in registers AA and QQ.

Next — Booth's Multiplication Algorithm

6 of 14

Page 7

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

7. Booth's Multiplication Algorithm

The Shift-and-Add algorithm fails for negative numbers (2's complement). Booth's Algorithm elegantly multiplies signed numbers without needing to convert them to positive first.

7.1 The Theory

Booth's algorithm looks at strings of 1s in the multiplier. A string like `011110` (decimal 30) can be computed as 25212^5 - 2^1 (32 - 2). This means we can replace four additions with one subtraction and one addition, speeding up the process.

7.2 Hardware Setup

  • MM: Multiplicand.
  • QQ: Multiplier.
  • AA: Accumulator (initially 0).
  • Q1Q_{-1}: A 1-bit register appended to the right of Q0Q_0 (initially 0).
  • Count: Set to nn.

Next — Booth's Algorithm Rules

7 of 14

Page 8

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

8. Booth's Algorithm Rules

The algorithm examines the pair of bits Q0Q_0 and Q1Q_{-1}.

8.1 Operation Steps

  • If Q0Q1=10Q_0Q_{-1} = 10: Subtract MM from AA (AAMA \leftarrow A - M). This marks the beginning of a string of 1s.
  • If Q0Q1=01Q_0Q_{-1} = 01: Add MM to AA (AA+MA \leftarrow A + M). This marks the end of a string of 1s.
  • If Q0Q1=00Q_0Q_{-1} = 00 or 1111: Do nothing. (We are in the middle of a string of 0s or 1s).

After performing the arithmetic (if any), perform an Arithmetic Shift Right (ASR) on the combined register AQQ1AQ Q_{-1}.

Note on ASR: When shifting right, the MSB (the sign bit of AA) remains unchanged, preserving the sign of the number. The old MSB also shifts right.

Decrement Count. Repeat until Count is 0. The final signed product is in AA and QQ.

Next — Hardware Division

8 of 14

Page 9

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

9. Hardware Division

Division is the most complex arithmetic operation in a CPU. It is essentially repeated subtraction and shifting. We divide a 2n2n-bit Dividend by an nn-bit Divisor, producing an nn-bit Quotient and an nn-bit Remainder.

9.1 Hardware Setup

  • MM: Divisor.
  • A,QA, Q: The 2n2n-bit Dividend is loaded across AA (upper half) and QQ (lower half). If the dividend is only nn bits, it goes into QQ, and AA is zeroed.
  • Count: Set to nn.

There are two main algorithms for binary division: Restoring and Non-Restoring.

Next — Restoring Division Algorithm

9 of 14

Page 10

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

10. Restoring Division Algorithm

This algorithm tries to subtract the divisor. If the result is negative, it "restores" the value by adding the divisor back.

10.1 Algorithm Steps

  • 1. Shift combined registers AA and QQ LEFT by 1 bit.
  • 2. Subtract Divisor MM from AA (AAMA \leftarrow A - M).
  • 3. Check the sign bit of AA (the MSB).
  • 4. If AA is Positive (MSB=0): The subtraction was successful. Set Q0=1Q_0 = 1.
  • 5. If AA is Negative (MSB=1): The subtraction failed. Set Q0=0Q_0 = 0. Restore AA by adding MM back (AA+MA \leftarrow A + M).
  • 6. Decrement Count. If Count 0\neq 0, loop back to step 1.

After nn loops, the Quotient is in QQ, and the Remainder is in AA.

Flaw: The restoration step (AA+MA \leftarrow A + M) wastes a clock cycle whenever the subtraction fails.

Next — Non-Restoring Division Algorithm

10 of 14

Page 11

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

11. Non-Restoring Division Algorithm

This algorithm optimizes division by eliminating the wasteful "restore" step. Instead of restoring AA and shifting, it shifts first and then adds.

11.1 The Logic

If AA becomes negative, we essentially subtracted MM when we shouldn't have. In the next step, we shift left (multiplying the error by 2, becoming 2M-2M) and then add MM.
(2M)+M=M(-2M) + M = -M.
This yields the exact same mathematical result as if we had restored
AA (+M+M), shifted left (×2\times 2), and then subtracted MM (M-M).

11.2 Algorithm Steps

  • 1. Shift AA and QQ LEFT.
  • 2. If sign of AA is 0 (positive): Subtract MM from AA.
    If sign of
    AA is 1 (negative): Add MM to AA.
  • 3. If new sign of AA is 0: Set Q0=1Q_0 = 1.
    If new sign of
    AA is 1: Set Q0=0Q_0 = 0.
  • 4. Decrement count and loop.
  • 5. Final Correction: After nn loops, if AA is negative, add MM to AA one last time to get the true positive remainder.

Next — Floating-Point Arithmetic

11 of 14

Page 12

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

12. Floating-Point Arithmetic

Adding and multiplying floating-point numbers requires coordination between the mantissas and the exponents.

12.1 Floating-Point Addition/Subtraction

You cannot add mantissas if the exponents are different (just like you can't add 1.5×1031.5 \times 10^3 to 2.0×1022.0 \times 10^2 directly).

  • 1. Compare exponents.
  • 2. Shift the mantissa of the smaller number to the RIGHT until the exponents match. (e.g., 2.0×1020.2×1032.0 \times 10^2 \to 0.2 \times 10^3).
  • 3. Add/Subtract the mantissas.
  • 4. Normalize the result (shift the mantissa and adjust the exponent) so it fits the IEEE 754 format.

Next — Floating-Point Multiplication

12 of 14

Page 13

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

13. Floating-Point Multiplication

Multiplication of floating-point numbers is actually simpler than addition because alignment isn't required.

13.1 Steps for FP Multiplication

  • 1. Add Exponents: Because the exponents are biased (E=e+127E = e + 127), simply adding them yields double bias: (e1+127)+(e2+127)=e1+e2+254(e_1 + 127) + (e_2 + 127) = e_1 + e_2 + 254. We must subtract the bias (127) once to get the correct new exponent.
  • 2. Multiply Mantissas: Use unsigned hardware multiplication.
  • 3. Determine Sign: XOR the two sign bits. (S1S2S_1 \oplus S_2).
  • 4. Normalize: If the multiplied mantissa is 2.0\ge 2.0, shift it right 1 bit and increment the exponent.

Modern GPUs are essentially massive arrays of hardware built specifically to execute these floating-point operations in parallel.

Next — Summary & Review Checklist

13 of 14

Page 14

Wink Notes

B.Tech CSE — 3rd Semester

Computer Organisation & Architecture

Unit - 1

14. Summary & Review Checklist

Unit 1 connects abstract math to physical logic circuits.

14.1 University Exam Checklist

  • Convert (12.625)10(-12.625)_{10} into IEEE 754 Single Precision format. Show the Sign, Biased Exponent in binary, and Mantissa.
  • Explain the flaw of the Restoring division algorithm and how Non-Restoring division fixes it.
  • Trace Booth's Multiplication Algorithm to multiply (5)×(7)(-5) \times (7) using 4-bit registers. Show the contents of A, Q, and Q-1 at each step.
  • Draw the block diagram of a hardware adder/subtractor and explain the role of the V (overflow) flag.
  • List the steps required for floating-point addition.

14.2 Systems Programming Interview Focus

  • Why is checking for equality (`a == b`) with floating-point numbers in C/C++/Java a bad idea? (Answer: Due to precision loss during normalization and truncation, 0.1+0.20.1 + 0.2 often equals 0.300000000000000040.30000000000000004 in IEEE 754).

14 of 14

Continue in this subject