Number Systems and Conversions: Decimal, Binary, Octal, and Hexadecimal
Overview: Decimal 13 is 8 plus 4 plus 1, so its binary form is 1101.
What is a Number System?
- In daily life, we count things using 10 digits: 0 to 9.
- An electronic switch has only two states: OFF (0 Volt) or ON (+5 Volts).
- Because of this, computers work only with two digits: 0 and 1.
- This 2-digit system is called the Binary System.
- An everyday example
- Think of carrying ₹1,000 cash in your pocket:
-
- Carrying one thousand ₹1 coins is heavy and confusing (like Binary
1111101000).
- Carrying one thousand ₹1 coins is heavy and confusing (like Binary
-
- Carrying ₹10 notes is much easier to count (like Octal).
The Four Primary Number Systems
- Every number system has a Base (also called Radix).
- Base (Radix): The total number of unique digits used in that number system.
- Decimal (Base 10) Digits: 0 to 9 Used by humans in daily life
- Binary (Base 2) Digits: 0 and 1 Directly understood by computer hardware
- Octal (Base 8) Digits: 0 to 7 1 Octal digit = Group of 3 binary bits
- Hexadecimal (Base 16) 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15) 1 Hex digit = Group of 4 binary bits
- Binary: 2
- Octal: 8
View diagram · The Four Digital Number Systems
Step-by-Step Number System Conversions
- Case A: Converting from Decimal to Any Other Base: The Golden Rules:
- For the whole number part: Keep dividing by the new base.
- For the decimal point part: Keep multiplying by the new base.
- 25 ÷ 2 = 12, remainder is 1 (LSB - Last digit)
- 12 ÷ 2 = 6, remainder is 0
- 6 ÷ 2 = 3, remainder is 0
- 3 ÷ 2 = 1, remainder is 1
- 1 ÷ 2 = 0, remainder is 1 (MSB - First digit)
Binary, BCD, Octal, and Hexadecimal Arithmetic
Overview: In four unsigned bits, 15 plus 1 gives 0000 with a carry.
Why Do Computers Need Special Arithmetic?
- Inside the CPU, the Arithmetic Logic Unit (ALU) performs millions of calculations every second.
- Computer chips cannot understand signs like
+or-. - They only understand high and low electrical voltages (1s and 0s).
- Designing separate electronic circuits for addition and subtraction is costly and wastes chip area.
- An everyday example
- Think of an old mechanical bike odometer.
- If it reads
00km and you roll the wheel backward by 1 km, it shows99km! - Complement arithmetic works the exact same way.
Binary Arithmetic Basics
- A. Binary Addition Rules: Start with the four two-bit cases, then include any carry from the previous column.
0 + 0 = 00 + 1 = 11 + 0 = 11 + 1 = 0(with a Carry of 1, because 2 in binary is10₂)1 + 1 + 1(when there is a previous carry) = 1 (with a Carry of 1, because 3 in binary is11₂)- B. How Computers Store Negative Numbers: How does computer memory know if a number is positive (
+5) or negative (-5)? - Sign-Magnitude Form:
View diagram · A. Binary Addition Rules
Subtraction using 2’s Complement (A - B)
- To calculate
A - B, the computer actually calculates: - The 3 Easy Steps: Find the 2’s complement of the number you are subtracting (B).
- Add this value to the first number (A).
- Check the extra carry at the left:
- If Carry = 1: Discard it!
- If Carry = 0: The answer is negative.
- Solved Example: Calculate 28 - 14 using 8-bit 2’s Complement: A = 28 in binary =
00011100 - B = 14 in binary =
00001110
View diagram · Solved Example: Calculate 28 - 14 using 8-bit 2’s Complement
BCD (Binary Coded Decimal) Arithmetic
- In BCD (8421 code), each decimal digit from 0 to 9 is written separately as a 4-bit group.
- Example: Decimal
25is written as0010 0101. - A 4-bit group can count up to 15 (
1111₂). - But decimal digits stop at 9 (
1001₂). - Therefore, patterns from 10 to 15 (1010 to 1111) are INVALID BCD.
- The Golden Rule of BCD Addition (+6 Rule): When adding two BCD numbers:
- Add them using standard binary addition.
- If any 4-bit group is greater than 9 OR produces a carry out:
View diagram · Solved Example: Add 35 + 48 in BCD
Octal and Hexadecimal Arithmetic
- Octal Arithmetic (Base 8): Uses digits 0 to 7.
- Addition: If the column sum is 8 or more, subtract 8 and carry 1 to the left.
- Subtraction: If you borrow from the left column, you borrow an amount of 8 (not 10).
- Right Column:
7 + 4 = 11. - Left Column:
1 (carry) + 5 + 3 = 9. - Result = (113)₈
- Hexadecimal Arithmetic (Base 16): Uses digits 0 to 9 and letters A to F.
- Addition: If the column sum is 16 or more, subtract 16 and carry 1 to the left.
Binary Codes, Decimal Codes, Gray Code, and Error Detection / Correction
Overview: A parity bit can flag a single changed bit, but it cannot tell you which position changed.
What are Binary Codes?
- Computers only understand electrical 0s and 1s.
- But as humans, we need to type our names, college roll numbers, symbols (
@,#), and phone numbers. - A Binary Code is simply a agreed-upon pattern of
0s and1s used to represent a specific character or number. - An everyday example
- When you sit for a university exam, DAVV gives you a unique Roll Number.
- The university database doesn’t search you by your nickname; it identifies you by that code.
- Binary codes do the exact same thing for computer data!
- Weighted Codes Each bit position carries a fixed weight (e.g., BCD 8421, 2421)
View diagram · Classification of Binary Codes
Decimal Codes: BCD and Excess-3
- A. BCD (Binary Coded Decimal / 8421 Code): A weighted code where each bit has a positional weight of 8, 4, 2, and 1.
- Each decimal digit (0 to 9) is represented using 4 bits:
- 0 =
0000, 5 =0101, 9 =1001. - Invalid BCD States: Numbers from 10 (
1010₂) to 15 (1111₂) are never allowed in standard BCD. - B. Excess-3 Code (XS-3): A non-weighted code made by adding 3 (
0011₂) to each BCD digit. - Formula: Excess-3 = BCD + 0011₂
- Decimal 0 →
0000 + 0011 = 0011 - Decimal 9 →
1001 + 0011 = 1100
Gray Code (Unit Distance Code)
- The Gray Code is a non-weighted code where only one single bit changes when going from one number to the next.
- Why Do We Need Gray Code?: In standard binary, going from 3 to 4 changes 3 bits at the exact same moment:
011→100(all three bits flip).- If one switch flips slightly faster than the others, the computer might read wrong intermediate data (like
010or111). - In Gray code, only 1 bit ever changes at any step.
- A. Binary to Gray Code Conversion: The first bit (MSB) stays the same:
G₃ = B₃. - For every next bit, do an XOR (⊕) between the current binary bit and the bit on its left:
Gᵢ = Bᵢ₊₁ ⊕ Bᵢ
Character Codes: ASCII vs. EBCDIC
- Computers need standard tables to recognize alphabets and keyboard symbols.
- Full Form: American Standard Code for Information Interchange
- Bits per Character: Originally 7 bits (128 characters); Extended is 8 bits (256 characters)
- Developed By: ANSI (Standard for modern PCs, Web, Linux, Windows)
- Code Sequence: Continuous (
AthroughZare numbers 65 to 90) - Usage Today: Foundation of modern internet and UTF-8
Error Detecting and Correcting Codes
- When data travels through cables or Wi-Fi, electrical noise can flip a
0into a1or a1into a0. - A. Parity Bit (Error Detection Only): A single extra check bit is added to the data:
- Even Parity: The total number of
1s (including parity) must be Even. - Odd Parity: The total number of
1s must be Odd. - Limitation: It only catches an odd number of errors (1, 3, 5).
- B. Hamming Code (Detection + Auto Correction): Invented by Richard Hamming, this code does two things:
- Detects that an error occurred.
- Identifies the exact bit location so the receiver can immediately flip it back to fix it!
Logic Gates: Basic, Universal, and Special Gates
Overview: For inputs 1 and 1, OR gives 1 and XOR gives 0.
What is a Logic Gate?
- Inside your laptop or smartphone, billions of tiny switches work together to make decisions.
- A Logic Gate is an electronic circuit with one or more inputs (
0or1) and produces exactly one output. - An input
0means Low Voltage (0V), and1means High Voltage (+5V). - An everyday example
- Think of college exam eligibility:
- “You need 75% attendance AND you must clear internal exams.”
- Only when both conditions are true, you get the admit card.
The Three Basic Logic Gates
- AND requires both inputs high and OR requires at least one high.
- AND Gate (•) Output is 1 ONLY when ALL inputs are 1.
- OR Gate (+) Output is 1 if AT LEAST ONE input is 1.
- NOT Gate (Inverter) Output is the OPPOSITE of the input.
- A. The AND Gate: Formula:
Y = A • B(or simplyAB) - Simple Rule: Output is
1only when both inputs A and B are1. - Truth Table:
- 0: 0
View diagram · The Three Fundamental Logic Operations
Universal Logic Gates: NAND and NOR
- Why Are They Called “Universal Gates”?: A gate is called Universal because you can build any other gate (AND, OR, NOT, XOR) using only NAND gates or **only…
- Chip factories love this because making just one type of gate in bulk saves huge manufacturing costs.
- A. The NAND Gate (NOT + AND): Formula:
Y = (A • B)' - It is an AND gate with a NOT bubble at its output.
- Simple Rule: Output is
0only when all inputs are1. - Truth Table:
- 0: 0
- 0: 1
Special Purpose Gates: XOR and XNOR
- XOR gives one when two input bits differ.
- XOR (Exclusive-OR) Output = 1 when inputs are DIFFERENT (Odd 1s detector)
- XNOR (Exclusive-NOR) Output = 1 when inputs are THE SAME (Equivalence detector)
- A. The XOR Gate (Exclusive-OR): Symbol: ⊕
- Formula:
Y = A ⊕ B = A'B + AB' - Simple Rule: Output is
1when inputs are different from each other. - Truth Table:
- 0: 0
Boolean Algebra and Karnaugh Map (K-Map) Simplification
Overview: Place adjacent ones in groups of one, two, four or eight cells.
Why Do We Simplify Boolean Expressions?
- Every extra logic gate inside a computer uses up silicon chip space, drains battery, generates heat, and slows down processing speed.
- Boolean Algebra and K-Maps help us reduce complicated equations to their simplest possible form.
- A smaller equation means fewer physical gates and a faster, cheaper computer circuit!
- An everyday example
- Imagine packing your college bag.
- Instead of carrying 5 separate heavy books for one subject, you carry one combined all-in-one notebook!
- That is what Boolean minimization does for computer chips: same result, but much lighter and faster.
Fundamental Laws of Boolean Algebra
- Identity Law: A • 1 = A
- Null Law: A • 0 = 0
- Idempotent Law: A • A = A
- Complement Law: A • A’ = 0
- Commutative Law: A • B = B • A
- Associative Law: (A • B) • C = A • (B • C)
De Morgan’s Theorems
- De Morgan’s rules are the most popular simplification tools in university exams.
- First Theorem: The complement of an AND is the OR of individual complements:
- Second Theorem: The complement of an OR is the AND of individual complements:
Canonical Forms: SOP and POS
- Sum of Products (SOP):
- Built using Minterms (
m). - Each minterm is a product (AND) of variables.
- Example:
F(A, B, C) = Σ m(1, 3, 5, 7) - Written out:
F = A'B'C + A'BC + AB'C + ABC - Product of Sums (POS):
- Built using Maxterms (
M). - Each maxterm is a sum (OR) of variables.
Karnaugh Map (K-Map) Simplification
- A K-Map is a graphical grid used to simplify logic functions without solving long algebraic formulas.
- Adjacent squares differ by only one single bit.
- This is why coordinates follow Gray code order:
00, 01, 11, 10. - Pair (Group of 2) Eliminates 1 variable
- Quad (Group of 4) Eliminates 2 variables
- Octet (Group of 8) Eliminates 3 variables
- Golden Rules for K-Map Grouping: Groups must always be in powers of 2: 1, 2, 4, 8, or 16 cells.
- Group only
1s for SOP expressions (or0s for POS).
View diagram · K-Map Grouping Hierarchy View diagram · Solved Example: 3-Variable K-Map
Introduction to Combinational and Sequential Circuits & Circuit Design
Overview: A calculator’s adder gives the same sum whenever its inputs match.
What are Digital Circuits?
- In digital electronics and computer hardware, all circuits belong to one of two big families:
- Combinational Circuits: Circuits with no memory.
- Sequential Circuits: Circuits with memory.
- An everyday example
-
- Combinational Circuit: Think of an ordinary light switch in your room.
-
- Sequential Circuit: Think of a ceiling fan remote button that changes speeds: Speed 1 → Speed 2 → Speed 3 → OFF.
Block Diagram Comparison
- A combinational circuit depends on the present inputs.
View diagram · Architectural Difference: Memory & Feedback
Key Differences: Combinational vs. Sequential
- Output Depends On: Only present inputs
- Memory Element: Not present
- Feedback Loop: None
- Clock Signal: Not needed
- Speed: Faster (no waiting for clock ticks)
- Design Difficulty: Easy to design
General Design Procedure for Combinational Circuits
- Whenever you design any new combinational circuit from scratch, follow these 4 standard steps:
- Problem Definition: Read the requirement and count how many input lines and output lines you need.
- Build Truth Table: List all input combinations (
2ⁿrows) and write down the required output for each row. - K-Map Simplification: Fill the K-Map with outputs and find the smallest SOP or POS equation.
- Draw Logic Diagram: Draw the final gate schematic using basic gates or universal gates.
Solved Circuit Design Problem: Majority Voter Circuit
- Problem Statement: Design a voting circuit for a 3-member college committee (
A,B,C). - Step 1: Truth Table: With 3 inputs (
A, B, C), there are2³ = 8possible voting combinations: - 0: 0
- 1: 0
- 2: 0
- 3: 0
- 4: 1
- 5: 1