1Unit 1

Digital Design Fundamentals & Number Systems

8h

Class hours

7

Topics

0%

0/41 done

Progress0/41 topics

Why This Unit Matters

From analog to digital — understand how computers represent and process information using binary, octal, and hexadecimal number systems.

Why This Unit Matters

Unit 1 is the absolute foundation of digital logic. Every concept in Units 2–5 — logic gates, flip-flops, memory, processors — operates on binary numbers. If you understand how binary, hex, and complements work, the rest of digital logic will feel natural. This unit also carries heavy weight in TU BCA exams: number conversions and complement subtraction appear in every single past paper from 2019–2025.

Unit Overview in Simple Words

1

Signals & Systems

Analog vs digital — why digital won.

2

Counting Systems

Binary, octal, decimal, hex — and how to convert between them.

3

Negative Numbers

2's complement — how computers handle subtraction with adder circuits.

4

Codes & Errors

BCD, Gray, ASCII, parity — how data is encoded and protected.

Learning Outcomes

1Convert numbers between binary, octal, decimal, and hexadecimal (including fractional parts)
2Perform binary addition, subtraction (2's complement), multiplication, and division
3Find 1's complement, 2's complement, 9's complement, and 10's complement
4Subtract numbers using complement method and interpret the result
5Represent signed numbers in sign-magnitude, 1's complement, and 2's complement forms
6Convert decimal numbers to IEEE 754 single-precision floating-point format
7Encode and decode BCD, Excess-3, Gray code, and ASCII
8Explain parity bits and Hamming code for error detection and correction
⏱️

Teaching Hours

8 hours

📌

Topics

7 main topics

🎯

Exam Weight

~25% of paper

⚠️

Must Know

Conversions + 2's complement

Analog and Digital

1.1 Analog and Digital Signals

Every physical quantity in the world — sound, temperature, voltage, speed — varies continuously. Electronics must work with these quantities in one of two ways: keep them continuous (analog) or convert them to discrete steps (digital).

Definition

Analog Signal

A signal that varies continuously and smoothly over time, taking any value within a range. Examples: audio sound waves, thermometer readings, radio waves, voltage from a microphone.

Definition

Digital Signal

A signal that takes only discrete, finite values — typically 0 and 1 (binary). Examples: computer data, CD audio, digital thermometer output, USB data.

Signal Comparison
Fig 1.1Analog (continuous) vs Digital (discrete) signal representation
PropertyAnalogDigital
Signal typeContinuous (infinite values)Discrete (finite values, 0 & 1)
RepresentationAny value in a rangeOnly 0 or 1 (binary)
Noise immunityPoor — noise degrades the signalExcellent — noise easily filtered
AccuracyLimited by noise and component tolerancesHigh for given bit-width; limited by quantization error
StorageDifficult, degrades over timeEasy, lossless (hard disk, RAM)
ProcessingRequires analog circuitsProgrammable, flexible
BandwidthEfficient — transmits signal directlyRequires more bandwidth than analog equivalent
CostLower for simple circuitsDecreasing rapidly (VLSI)
ExamplesAM/FM radio, vinyl recordsCDs, DVDs, computers, phones

📝 Note

Both analog and digital systems are used in practice. Digital dominates computing and communications; analog is still preferred for high-frequency RF circuits, precision analog sensing, and audio amplification where continuous signal fidelity matters.

🎯 Exam Focus

Analog vs Digital comparison table is a frequent short-answer question. Remember: Digital is better for noise immunity, storage, and processing. Analog is still used where continuous variation matters (e.g., sensors, audio amplifiers).

1.2 Analog and Digital Systems

Definition

Digital System

A system that processes, stores, or transmits information using discrete binary values (0 and 1). The physical realization uses transistors operating as switches (ON = 1, OFF = 0).

Advantages of Digital Systems over Analog Systems:

🛡️

Noise Immunity

Digital signals can be regenerated perfectly. Even if noise distorts the signal, a threshold circuit restores clean 0 or 1.

💾

Easy Storage

Digital data stored in RAM, ROM, flash memory without degradation. Analog recordings degrade over time.

🔁

Reproducibility

Digital copies are perfect — 1000 copies of a digital song are identical to the original.

💻

Programmability

The same digital hardware can perform different tasks by changing software (program).

Speed

Modern digital circuits operate at GHz frequencies. Billions of operations per second.

🧩

Integration (VLSI)

Billions of transistors on a single chip. Impossible with analog circuits at this density.

🔒

Security

Digital data can be encrypted using well-established algorithms (AES, RSA). Analog encryption exists but is far less practical and widely used.

📡

Compatibility

Digital systems from different manufacturers can communicate using standard protocols (USB, Ethernet).

💡 Remember

Remember the 8 advantages using: "NRIPSCSC" — Noise immunity, Reproducibility, Integration, Programmability, Speed, Compatibility, Security, low Cost.

Number Systems & Conversions

1.3 Number System Representation

A positional number system represents values using symbols (digits), where each symbol's value depends on its position(place value) within the number. The base (or radix) determines how many unique digits the system uses and what the place values are.

📐 Formula

For a number with digits dndn-1...d1d0 in base r:
Value = dn×rn + dn-1×rn-1 + ... + d1×r1 + d0×r0

The Four Number Systems

SystemBase (Radix)DigitsExamplePrefix/Suffix
Binary20, 1(1010)₂ = 10₁₀Subscript ₂ or prefix 0b
Octal80 – 7(17)₈ = 15₁₀Subscript ₈ or prefix 0o
Decimal100 – 9(255)₁₀No prefix (default)
Hexadecimal160–9, A–F(FF)₁₆ = 255₁₀Subscript ₁₆ or prefix 0x

🎯 Exam Focus

In TU exams, always write the base as a subscript: (1011)₂ not just 1011. The Hexadecimal digits A=10, B=11, C=12, D=13, E=14, F=15 must be memorised.

1.4 Number System Conversions

1.4.1 Binary Number System (Base 2)

Binary uses only two digits: 0 and 1. Each position is a power of 2. The rightmost position is 2⁰, next is 2¹, then 2², and so on.

Binary Place Values
Fig 1.2Positional weight of each bit in (1101011)₂ = 107₁₀
Binary to Decimal ConverterInteractive

Enter a binary number (e.g. 11010) to see its decimal value with a step-by-step breakdown.

1.4.2 Octal Number System (Base 8)

Octal uses digits 0–7. Each octal digit corresponds to exactly 3 binary digits. This makes Binary ↔ Octal conversion trivially easy — just group bits in threes.

💡 Remember

Shortcut — Binary ↔ Octal:
Group binary digits in sets of 3 from the right. Replace each group with its octal equivalent.
(110 111 010)₂ → 6 7 2 → (672)₈

Binary ↔ Octal Quick Reference

0(000)₂
1(001)₂
2(010)₂
3(011)₂
4(100)₂
5(101)₂
6(110)₂
7(111)₂

1.4.4 Hexadecimal Number System (Base 16)

Hexadecimal uses 16 symbols: 0–9 and A–F. Each hex digit represents exactly 4 binary digits — making it the preferred way to represent binary data in a compact, readable form.

Hexadecimal Reference Table

Hex0123456789ABCDEF
Dec0123456789101112131415
4-bit0000000100100011010001010110011110001001101010111100110111101111

💡 Remember

Shortcut — Binary ↔ Hex:
Group binary digits in sets of 4 from the right. Replace each group with its hex equivalent.
(1010 1111 0011)₂ → A F 3 → (AF3)₁₆
Interactive Tool

Interactive Number Converter

Convert between Binary, Octal, Decimal & Hex — with step-by-step working

Input is:

BIN — Base 2

101010

OCT — Base 8

52

DEC — Base 10

42₁₀

input

HEX — Base 16

2A₁₆

⚠️ Common Mistake

Most common mistakes in conversions:
  • Forgetting to read remainders bottom-to-top in division method
  • Reading multiplication results top-to-bottom (correct) vs bottom-to-top (wrong)
  • Confusing groups of 3 (Binary↔Octal) with groups of 4 (Binary↔Hex)
  • Not padding to correct group size when converting (e.g., only 2 bits left — pad to 3 with leading zeros)
  • Writing hex letters in lowercase (use uppercase: A not a)

Signed Numbers & IEEE 754

1.5 Representation of Signed Numbers

Unsigned binary can only represent positive numbers. To represent both positive and negative, computers use one of three conventions — all using the most significant bit (MSB)as a sign indicator (0 = positive, 1 = negative).

Sign-Magnitude

MSB = sign bit. Remaining bits = magnitude.

+5 in 4-bit:0 101
−5 in 4-bit:1 101

✓ Pros:

  • Simple concept
  • Easy to read magnitude

✗ Cons:

  • +0 and −0 both exist
  • Arithmetic is complex

1's Complement

MSB = sign bit. Negative = flip all bits of positive.

+5 in 4-bit:0101
−5 in 4-bit:1010

✓ Pros:

  • Easier addition than sign-mag

✗ Cons:

  • +0 (0000) and −0 (1111) still exist
  • End-around carry in addition

2's Complement

MSB = sign bit. Negative = 1's comp + 1. STANDARD method.

+5 in 4-bit:0101
−5 in 4-bit:1011

✓ Pros:

  • Unique zero (only 0000)
  • Addition and subtraction work directly
  • Used in ALL modern CPUs

✗ Cons:

  • Asymmetric range: −8 to +7 (4-bit)
🧮

Signed Number Explorer

Toggle the bits to see how the representation changes.

Click to toggle bits

MSB
64
32
16
8
4
2
1

Unsigned

5

Sign-Magnitude

5

1's Complement

5

STANDARD

2's Complement

5

Comparison: Representing −5 through −8 in 4-bit

DecimalUnsigned (4-bit)Sign-Magnitude1's Complement2's Complement
+70111011101110111
+60110011001100110
+50101010101010101
+40100010001000100
+30011001100110011
+20010001000100010
+10001000100010001
+00000000000000000
−010001111
−1100111101111
−2101011011110
−3101111001101
−4110010111100
−5110110101011
−6111010011010
−7111110001001
−81000

🎯 Exam Focus

2's complement is the only method asked in most TU exam questions. Range of n-bit 2's complement: −2n−1 to +2n−1−1. For 8-bit: −128 to +127. For 4-bit: −8 to +7.

1.5 (continued) IEEE 754 Floating-Point ✦ Exam practice

✦ Note on Syllabus Scope

IEEE 754 is not explicitly listed in the official TU BCA CACS 103 syllabus, but it has appeared in TU past papers (2022, 2023, 2025). It is included here for exam preparation. Prioritise signed-number representations and complement arithmetic from the core syllabus first.

The IEEE 754 standard defines how floating-point numbers (numbers with a decimal point) are stored in binary. It uses a format inspired by scientific notation: value = (−1)^S × 1.M × 2^(E−Bias).

IEEE 754 Formats

PropertySingle Precision (32-bit)Double Precision (64-bit)
Total bits3264
Sign bit (S)1 bit1 bit
Exponent (E)8 bits11 bits
Mantissa (M)23 bits52 bits
Bias1271023
Exponent range−126 to +127−1022 to +1023
Decimal range±3.4 × 10³⁸±1.8 × 10³⁰⁸
Precision~7 decimal digits~15 decimal digits

Single-Precision 32-bit Layout

Sign1 bitbit 31
Exponent8 bitsbits 30–23+ 127 bias
Mantissa (Fraction)23 bitsbits 22–0Implicit leading 1
1

Sign bit

−23.375 is negative, so S = 1
2

Convert magnitude to binary

23 = (10111)₂ | 0.375: 0.375×2=0.75(0), 0.75×2=1.5(1), 0.5×2=1.0(1) → 0.375 = (.011)₂
So 23.375 = (10111.011)₂
3

Normalize

10111.011 = 1.0111011 × 2⁴
(shift decimal 4 places left to get 1.XXXXX form)
4

Biased exponent

Actual exponent = 4
Biased exponent = 4 + 127 = 131 = (10000011)₂
5

Mantissa (23 bits, drop implicit 1)

0111011 → pad to 23 bits → 01110110000000000000000
6

Assemble 32-bit word

S=1 | Exp=10000011 | Mantissa=01110110000000000000000
= 1 10000011 01110110000000000000000
Hex = 0xC1BB0000

🎯 Exam Focus

IEEE 754 is asked in 2022, 2023, and 2025 TU papers. Key facts to remember: Single = 32-bit, bias = 127. Double = 64-bit, bias = 1023. The leading 1 before the decimal point is NOT stored (implicit/hidden bit) — saves 1 bit of precision.
Interactive Tool
🔬

IEEE 754 Single-Precision Converter

32-bit floating point — 1 sign + 8 exponent + 23 mantissa

32-bit IEEE 754 Layout

1
Sign (1)
|
10000011
Exp (8) = 131
|
01110110000000000000000
Mantissa (23)

Hex

0xC1BB0000

Normalized form

1.01110110000000000000000 × 24

Sign bit:1 = negative
Exponent:4 + 127 = 131
Mantissa:23-bit fractional part
1Step 1 — Sign bit: 1 (number is negative (−))
2Step 2 — Convert |-23.375| to binary: 10111.011
3Step 3 — Normalize: 1.0111011 × 2^4
4Step 4 — Biased exponent = 4 + 127 = 131 = (10000011)₂
5Step 5 — Mantissa (23 bits, drop leading 1): 01110110000000000000000
6Step 6 — Final 32-bit IEEE 754: 1 | 10000011 | 01110110000000000000000

IEEE 754 Quick Reference

Single (32-bit)

1 sign + 8 exponent + 23 mantissa | Bias = 127

Double (64-bit)

1 sign + 11 exponent + 52 mantissa | Bias = 1023

Formula: (−1)^S × 1.M × 2^(E−Bias)

Complements

1.6 Complements

Complements are used to simplify subtraction — instead of building subtractor hardware, computers add the complement of a number. There are two types of complements for a number system with radix (base) r:

Definition

(r−1)'s Complement

For a base-r number with n digits, the (r−1)'s complement is (rn − 1) − N. For binary (r=2): flip all bits. For decimal (r=10): subtract each digit from 9.

Definition

r's Complement

For a base-r number with n digits, the r's complement is rn − N. Equivalently: (r−1)'s complement + 1. For binary: flip bits + 1. For decimal: 9's complement + 1.

(r−1)'s Complement Formula

(r^n − 1) − N

n = number of digits; r = base (radix)

r's Complement Formula

r^n − N = (r−1)'s comp + 1

OR: find (r−1)'s complement, then add 1

🎯 Exam Focus

You will almost certainly see a question: "Find the 2's complement of X" or "Subtract using 2's complement." Know both formulas and the shortcut: for 2's complement, scan from right, copy bits up to and including the first 1, then flip all bits to the left of it.

Decimal (Base-10) Complements

9's Complement (Base 10, r−1)

Subtract each digit from 9.

Formula: (10n − 1) − N

Example: 9's complement of 52520

999999052520
= 947479

Digit by digit: 9−0=9, 9−5=4, 9−2=7, 9−5=4, 9−2=7, 9−0=9

10's Complement (Base 10, r)

9's complement + 1. Or: leave trailing zeros, subtract first non-zero digit from 10, subtract remaining digits from 9.

Formula: 10n − N

Example: 10's complement of 52520

9's comp:947479
+ 1 : 1
= 947480

Verify: 52520 + 947480 = 1,000,000 = 106

Decimal Complement Quick Reference

N (4-digit)9's Complement10's Complement
000099990000 (special: 10's comp of 0 = 0)
123487658766
500049995000
987501240125
000199989999

Binary Complements

1's Complement (r−1 for binary)

Flip every bit: 0 → 1, 1 → 0

Formula: (2n − 1) − N

Example: 1's complement of (1010 1100)₂

Original:
10101100
1's comp:
01010011

10101100 → 01010011 (each bit flipped)

💡 Remember

Shortcut: Just flip every 0 to 1 and every 1 to 0. All 8 bits, no carry needed.

2's Complement (r for binary)

1's complement + 1

Formula: 2n − N

Example: 2's complement of (1010 1100)₂

1's comp:
01010011
+ 1:00000001
2's comp:
01010100

01010011 + 1 = 01010100

💡 Remember

Fast shortcut: Scan from the right (LSB). Copy all bits up to and including the first 1 you encounter. Then flip all remaining bits to the left.
Example: 10101100 → copy 00, then copy 1 → 01010100
🔢

Complement Calculator

1's complement · 2's complement · Subtraction via complement

Bit width:

= (77)₁₀ — 8-bit unsigned

Original

01001101

(01001101)₂ = 77₁₀

1's Complement — flip every bit

Rule: 0 → 1, 1 → 0

10110010

(10110010)₂ = 178₁₀ (unsigned) | represents -77₁₀

2's Complement — 1's complement + 1

Step 1: 1's comp = (10110010)₂  →  Step 2: add 1

10110011

(10110011)₂ represents -77₁₀ in 2's complement

💡 2's complement is the standard way to represent negative numbers in modern computers. MSB = 1 means negative, MSB = 0 means positive.

🎯 Exam Focus

Common exam question: "Find the 1's and 2's complement of 10110010." Always show both methods clearly. Many students lose marks by not showing the intermediate 1's complement step when computing 2's complement.

Subtraction Using Complements

Instead of building subtractor circuits, digital computers compute A − B by adding the complement of B to A. This is why complement arithmetic is so important in digital logic.

Algorithm: A − B using r's Complement

  1. Find the r's complement of B (subtrahend)
  2. Add r's complement of B to A (minuend)
  3. If carry out of MSB occurs: discard the carry → result is positive (A ≥ B)
  4. If NO carry out of MSB: result is in complement form → take r's complement of the result and attach a − sign (A < B)
2's Complement Subtraction: 1010₂ - 0110₂1/5
Step 1: Identify A and B

A (minuend) = 1010 (= 10₁₀)

B (subtrahend) = 0110 (= 6₁₀)

We want A - B = 10 - 6 = 4

Binary Subtraction Examples

Complement Types — Summary

TypeBaseFormulaShortcut
9's complement10(10ⁿ − 1) − NSubtract each digit from 9
10's complement1010ⁿ − N9's comp + 1
1's complement2(2ⁿ − 1) − NFlip all bits (0↔1)
2's complement22ⁿ − N1's comp + 1 (or copy from LSB to first 1, then flip)

⚠️ Common Mistake

Mistake 1: Forgetting to pad B to the same number of digits as A before finding its complement. If A has 5 digits and B has 4 digits, pad B with a leading zero first!

Mistake 2: When there is no carry (negative result), students forget to take the complement of the result and just report the raw sum as the answer.

Binary Arithmetic

1.7 Binary Arithmetic

Binary Addition

Binary addition follows the same column-by-column process as decimal addition, but with only two digits (0 and 1). When the sum of a column exceeds 1, a carry is propagated to the next column.

Four Basic Rules

0+0
Sum:0
Carry:0
0+1
Sum:1
Carry:0
1+0
Sum:1
Carry:0
1+1
Sum:0
Carry:1

Rule 4: 1 + 1 = 10₂ → write 0, carry 1 (just like decimal: 9 + 1 = 10, write 0, carry 1)

Binary Addition: 1011 + 1101 (step by step)1/6
Step 1: Align numbers

1 0 1 1

+ 1 1 0 1

─────────

Write both numbers right-aligned. We add column by column from right (bit 0) to left.

Worked Examples

📝

Interactive Arithmetic Solver

Watch addition carries and subtraction borrows propagate in real time.

Bit width:

= 11₁₀

= 6₁₀

0
0
0
1
1
1
0
0
0
0
0
0
1
0
1
1
+
0
0
0
0
0
1
1
0
0
0
0
1
0
0
0
1

Result: 00010001 = 17₁₀

Binary Subtraction

Direct subtraction uses borrow logic. In practice, digital systems use the 2's complement method (convert to addition) instead.

Direct Subtraction Rules

00
Diff:0
Borrow:0
01
Diff:1
Borrow:1
10
Diff:1
Borrow:0
11
Diff:0
Borrow:0

Rule 2: 0 − 1: borrow from left. Borrowed bit = 2₁₀, so 2 − 1 = 1. The left column loses 1 due to the borrow.

Binary Multiplication

Binary multiplication uses the same long multiplication process as decimal, but is much simpler because each partial product is either 0 (if multiplier bit = 0) or the multiplicand itself (if multiplier bit = 1). Partial products are shifted left and summed.

Four Basic Rules

0×0
0
0×1
0
1×0
0
1×1
1

💡 Remember

Pattern: Each partial product is the multiplicand shifted left by the position of the multiplier bit. If the multiplier bit is 0, write all zeros. If it's 1, write the multiplicand. Then add all partial products using binary addition.

Binary Division

Binary division mirrors decimal long division. Since only two digits exist, at each step you ask: "Can the divisor fit into the current dividend portion?" If yes → quotient bit = 1, subtract. If no → quotient bit = 0, bring down next bit.

🎯 Exam Focus

Binary division is rarely asked beyond the basic concept. Focus more on addition and 2's complement subtraction for exams. Multiplication questions do appear — practice partial products and addition of shifted rows.

Overflow in Binary Arithmetic

Unsigned Overflow

Occurs when the result of an addition is too large for the available bits. Detected by a carry out of the most-significant bit (MSB).

8-bit max unsigned: 255. If result > 255 → overflow.

Signed Overflow (2's complement)

Occurs when adding two numbers of the same sign gives a result of the opposite sign. Detected when: carry into MSB ≠ carry out of MSB.

8-bit 2's comp range: −128 to +127. Result outside this range → overflow.

Signed Overflow Detection Rules

OperationOverflow occurs when...Example (8-bit)
+ + +Two positive numbers → negative result01100100 + 01100100 = 11001000 (−56 instead of +200)
− + −Two negative numbers → positive result11000000 + 11000000 = 10000000 (wrong sign)
+ + −Never — mixed signs cannot overflow01111111 + 10000001 = 00000000 (fine, = 0)

Binary Arithmetic — Quick Summary

Addition

Column-by-column; carry propagates left; 1+1=10₂

Subtraction

Direct (borrow method) or 2's complement (preferred)

Multiplication

Partial products (shift + copy/zero); add all rows

Division

Long division; quotient bit = 1 if divisor fits, else 0

⚠️ Common Mistake

Mistake 1: In multiplication, forgetting to shift each partial product left by the position of the multiplier bit. The partial product for multiplier bit at position k must be shifted left by k places.

Mistake 2: Writing the wrong number of bits in the result. If multiplying two 4-bit numbers, the product can require up to 8 bits. Don't truncate the result prematurely.

Binary Codes

1.8 Binary Codes

Digital systems use binary codes to represent letters, numbers, symbols, and instructions. Different codes are designed for different purposes: some optimize for human readability, some minimize errors during transmission, and some detect/correct transmission errors.

BCD (8421)

Decimal digits in binary — used in calculators, digital meters

Excess-3

Self-complementing code — used in older arithmetic circuits

Gray Code

Only 1 bit changes between consecutive values — used in encoders, error reduction

ASCII

7-bit code for text characters — standard for computers

Parity

Error detection — adds 1 check bit to detect single-bit errors

Hamming Code

Error correction — can detect and correct single-bit errors

🔄

Live Code Converter

Convert between Decimal, BCD, Excess-3, and Gray code.

BCD (8421)

60110
70111
50101

Excess-3 (XS-3)

6+3=91001
7+3=101010
5+3=81000

BCD Code (Binary Coded Decimal)

Definition

BCD (8421 Code)

Each decimal digit (0–9) is encoded separately as a 4-bit binary group. The weights of the bits are 8, 4, 2, 1 (hence "8421 code"). Valid BCD digits: 0000 to 1001. Codes 1010 to 1111 are invalid in BCD.

BCD Code Table (0–9)

Decimal0123456789
BCD0000000100100011010001010110011110001001

⚠️ Common Mistake

BCD ≠ Binary! The BCD for 25 is 0010 0101 (8 bits), NOT 00011001 (25 in pure binary). BCD converts each digit separately. Also: codes 1010–1111 are invalid in BCD — never use them.

Excess-3 Code (XS-3)

Definition

Excess-3 (XS-3) Code

An unweighted code derived by adding 3 (= 0011₂) to each BCD digit. Excess-3 is a self-complementing code: the 9's complement of any digit equals the 1's complement of its Excess-3 representation — useful for decimal arithmetic in older hardware.

Conversion Rule

XS-3 = BCD + 0011₂ = Decimal + 3 (then convert to 4-bit binary)

Excess-3 Code Table

DecimalBCD (4-bit)+3XS-3
00000+3 = 30011
10001+3 = 40100
20010+3 = 50101
30011+3 = 60110
40100+3 = 70111
50101+3 = 81000
60110+3 = 91001
70111+3 = 101010
81000+3 = 111011
91001+3 = 121100

💡 Remember

Self-complementing property: For any digit d, the Excess-3 of (9−d) equals the 1's complement of Excess-3(d). Example: XS-3(4) = 0111, and XS-3(5) = 1000 = 1's complement of 0111. This makes 9's complement subtraction hardware very simple.

Gray Code (Reflected Binary Code)

Definition

Gray Code

A binary code where only one bit changes between any two consecutive values. This minimizes errors in physical systems (encoders, A/D converters) where multiple bits changing simultaneously could cause transient errors.

Gray Code Conversion Rules
Fig 1.4Binary-to-Gray and Gray-to-Binary conversion using XOR operations

4-bit Gray Code Table (0–15)

DecimalBinaryGrayBit changed
000000000-
100010001bit 0
200100011bit 1
300110010bit 0
401000110bit 2
501010111bit 0
601100101bit 1
701110100bit 0
810001100bit 3
910011101bit 0
1010101111bit 1
1110111110bit 0
1211001010bit 2
1311011011bit 0
1411101001bit 1
1511111000bit 0

ASCII Code

Definition

ASCII (American Standard Code for Information Interchange)

A 7-bit code that represents 128 characters including uppercase letters (A–Z), lowercase letters (a–z), digits (0–9), punctuation, and control characters. Extended ASCII uses 8 bits (256 characters) for additional symbols.

Important ASCII Values (Must Memorize for Exams)

CharacterDecimalHexBinary (7-bit)
NUL (null)000000 0000
Space3220010 0000
'0'4830011 0000
'9'5739011 1001
'A'6541100 0001
'Z'905A101 1010
'a'9761110 0001
'z'1227A111 1010
DEL1277F111 1111

💡 Remember

Key relationships to remember:
  • 'A' = 65 (41H), 'a' = 97 (61H) → lowercase = uppercase + 32 (set bit 5)
  • '0' = 48 (30H) → digit '0'–'9' = 48–57
  • Space = 32, which is less than all printable characters

Parity Bit (Error Detection)

Definition

Parity Bit

An extra bit added to a binary word to make the total number of 1s either even (even parity) or odd (odd parity). A parity bit can detect (but not correct) a single-bit error.

Even Parity

The parity bit is chosen so the total number of 1s (including parity bit) is even.

Data: 1100011(five 1s → odd)
Parity bit:1(make total 1s even = 6)
Transmitted:11100011

Odd Parity

The parity bit is chosen so the total number of 1s (including parity bit) is odd.

Data: 1100011(five 1s → odd)
Parity bit:0(keep total 1s odd = 5)
Transmitted:01100011

🎯 Exam Focus

Limitation of parity: Parity can only detect an odd number of bit errors. If exactly 2 bits are flipped, parity still looks valid — the error goes undetected. Parity cannot correct errors, only detect them.

Hamming Code (Error Correction)

Definition

Hamming Code

An error-correcting code that adds multiple parity bits (check bits) at positions that are powers of 2 (1, 2, 4, 8...). It can detect up to 2-bit errors and correct single-bit errors by identifying the exact position of the error.

Number of Check Bits Required

For m data bits, the number of check bits r must satisfy: 2r ≥ m + r + 1

Data bits (m)Check bits (r)Total bits (m+r)
123
235
336
437
549
6410
7411
8412

🎯 Exam Focus

Know the Hamming code formula 2r ≥ m + r + 1 and the check bit positions (powers of 2). A typical exam question: "How many check bits are needed for 11 data bits?" → Try r=4: 2⁴=16 ≥ 11+4+1=16. Yes, r=4.

Code Comparison Table

CodeBitsWeighted?Primary UseKey Feature
BCD (8421)4/digitYes (8,4,2,1)Decimal displayInvalid codes 1010–1111
Excess-34/digitNo (unweighted)Arithmetic circuitsSelf-complementing
GrayVariableNoEncoders, A/D convertersOnly 1 bit changes per step
ASCII7 (or 8)NoText in computers128 characters; 'A'=65
Even Parity1 extraNoError detectionDetects odd-number of errors
Hammingr extraNoError correctionCorrects 1-bit errors

Practice & Self-Assessment

Active Recall Questions

Try to answer each question from memory before revealing the answer. This is the most effective study technique for long-term retention.

1

What is the difference between an analog signal and a digital signal?

2

Convert (11010110)₂ to hexadecimal. Show your method.

3

Find the 2's complement of (10110100)₂. Explain the method used.

4

What are the 4 advantages of digital systems over analog systems? Give one example for each.

5

Explain BCD code. Why is it different from binary? Convert 937₁₀ to BCD.

Exam-Style Questions

These questions match the style and marks distribution of TU BCA (BCA 103) past papers. Attempt each question before revealing the full solution.

Q1. Convert 165.625₁₀ to binary. [4 marks]

4 marks

Q2. Subtract (10110)₂ − (01101)₂ using 2's complement method. [5 marks]

5 marks

Q3. Find the IEEE 754 single-precision representation of −12.5₁₀. [6 marks]

6 marks

Q4. What is Gray code? Convert 14₁₀ to Gray code. [4 marks]

4 marks

Q5. Explain signed number representation. Write the range of 8-bit 2's complement numbers. [5 marks]

5 marks

Mini-Test

8 multiple-choice questions covering all of Unit 1. Answer all questions, then submit to see your score and explanations.

8 questionsAll Unit 1 topicsInstant scoring

1. What is the decimal value of (1010.01)₂?

2. The 2's complement of 11010 is:

3. Which number is INVALID in BCD?

4. In Excess-3 code, the decimal digit 6 is represented as:

5. Gray code is preferred over binary in position encoders because:

6. The bias in IEEE 754 single-precision floating point is:

7. How many check bits (parity bits) are needed for a Hamming code protecting 11 data bits?

8. Subtract 12 − 9 using 4-bit 2's complement. The result is:

How to Remember Unit 1

How to Remember Unit 1

Unit 1 is dense with procedures and tables. Here are proven memory shortcuts — mnemonics, visual anchors, and algorithmic patterns — that make recall effortless in exams.

Mnemonics

Advantages of Digital Systems

NRIPSCSC

NNoise immunity
RReproducibility
IIntegration (VLSI)
PProgrammability
SSpeed
CCompatibility
SSecurity
Clow Cost (decreasing)

Number Bases Mnemonic

BOHD

BBinary (base 2) — bits 0,1
OOctal (base 8) — digits 0–7
HHexadecimal (base 16) — 0–9, A–F
DDecimal (base 10) — digits 0–9

Signed Number Representations

S-1-2

SSign-Magnitude: MSB=sign, rest=magnitude
11's Complement: flip all bits for negative
22's Complement: flip all bits + 1 for negative

IEEE 754 Field Sizes (Single)

1-8-23

1Sign bit (1 bit)
8Exponent (8 bits), bias = 127
23Mantissa/fraction (23 bits)
Total = 32 bits

Procedural Memory Tricks

Integer → Binary (Division Method)

Divide repeatedly by 2. Collect remainders. READ THEM BOTTOM TO TOP (like reading up a ladder).

13 ÷ 2: 6R1 → 3R0 → 1R1 → 0R1 ↑ Read up: 1101
✖️

Fraction → Binary (Multiplication Method)

Multiply repeatedly by 2. Collect integer parts. READ THEM TOP TO BOTTOM (like reading down a list).

0.625×2=1.25→1, 0.25×2=0.5→0, 0.5×2=1.0→1 ↓ = .101
🔄

2's Complement Shortcut

Scan from LSB (right). Copy all bits UP TO AND INCLUDING the first 1. Then FLIP all remaining bits to the left.

1 0 1 1 0 1 0 0 → copy 00, copy 1 → 0 1 0 0 1 1 0 0
🔗

Binary ↔ Hex: Groups of 4

Group binary digits in sets of 4 from the right. Each group = one hex digit. For fractions, group from the radix point leftward and rightward.

1101 0110 → D6₁₆ | A3₁₆ → 1010 0011
🔗

Binary ↔ Octal: Groups of 3

Group binary digits in sets of 3 from the right. Each group = one octal digit.

001 101 110 → 156₈ | 37₈ → 011 111
🧮

9's Complement of Decimal

Subtract each digit from 9. No carrying needed — it's always digit-by-digit.

9's comp of 4637: 9−4=5, 9−6=3, 9−3=6, 9−7=2 → 5362

Code Memory Shortcuts

🔢

BCD Rule

BCD = each decimal digit gets its own 4-bit binary code. Only 0000–1001 are valid. Think: 'decode each digit separately, never cross digits.'

25 in BCD = 0010 0101 (NOT 00011001)

Excess-3 = BCD + 3

Always add 3 to the decimal digit, then convert to 4-bit binary. For decoding: subtract 3 from the binary value.

7 → 7+3=10 → 1010 | XS-3 code 1100 → 1100=12 → 12−3=9
🔀

Gray Code: XOR Down the Column

MSB copies directly. Every other bit = XOR of the two binary bits above the gap. For reverse: MSB copies, then XOR previous binary with current gray.

Bin 1011 → G: 1, 1⊕0=1, 0⊕1=1, 1⊕1=0 → Gray 1110
🔤

ASCII Key Values

Remember: 'A'=65, 'a'=97 (lowercase = uppercase + 32), '0'=48. Space=32 (lowest printable). All fit in 7 bits (0–127).

'B'=66, 'b'=98, '5'=53 (48+5)

Visual Memory Anchors

Binary Place Values — Powers of 2

Remember this row of powers:

2^7128
2^664
2^532
2^416
2^38
2^24
2^12
2^01

Trick: start at 1 (right) and double leftward: 1, 2, 4, 8, 16, 32, 64, 128

Hex Digit Values

The letter digits A–F:

A=10
B=11
C=12
D=13
E=14
F=15

Trick: A=10 (think: A is the 10th letter if we count from 1). Then B=11, C=12... F=15.

Quick Revision Summary

Before the Exam: Unit 1 Checklist

Can convert between binary, octal, decimal, hex (with fractions)
Know the 4 basic binary addition rules and carry propagation
Can perform 2's complement subtraction step-by-step
Can find 1's and 2's complement of any binary number
Know 9's and 10's complement procedure for decimal
Can write the 4-bit Gray code table from 0 to 15
Can convert decimal to BCD and back
Know Excess-3 = BCD + 3 and why it's self-complementing
Know IEEE 754 format (1+8+23, bias=127) and can convert example
Know 8-bit 2's complement range: −128 to +127
Can calculate number of Hamming check bits for m data bits
Know 'A'=65, 'a'=97, '0'=48 in ASCII
BCAStudyHub

Your complete interactive study guide for TU BCA Semester I — covering all subjects with interactive tools, past papers, and exam prep.

TU BCASemester I

Program Info

University
Tribhuvan University
Program
BCA — Bachelor in Computer Application
Semester
I (First)
Subjects
5 (4 live, 1 coming soon)

Made by SawnN