Course: EE 313 - Logic Circuits and Switching Theory
Module 1: Number Systems and Codes
Introduction
Number systems and coding techniques are the building blocks of modern digital electronics.
Every piece of information that passes through a computer, mobile device, or digital system is
represented using numbers and codes. Whether you are designing a logic circuit, programming a
microcontroller, or analyzing switching systems, a strong foundation in number systems is
essential.
In this module, you will learn:
The concept of different number systems (decimal, binary, octal, and hexadecimal).
Conversion methods between bases.
Applications of number systems in digital design.
Coding schemes such as BCD, ASCII, and Gray code.
How number systems and codes are used in real-world devices.
By the end of this module, you should be able to confidently convert, interpret, and apply
number systems in the context of logic circuits and switching theory.
�Did You Know?
The binary system (using only 0 and 1) was first fully described in 1703 by German
mathematician Gottfried Wilhelm Leibniz. Centuries later, it became the language of computers.
Understanding Number Systems
A number system is a way of expressing numbers using a consistent set of symbols (called digits)
and a base (or radix). The base determines how many digits are available and how place values are
assigned.
In general, a number in any base can be expressed as:
N = dn × bn + dn-1 × bn-1 + ⋯ + d1 × b1 + d0 × b0
Where:
• N = the number
• d = digit at a given position
• b = base (radix)
• n = position of the digit
For example, in the decimal number 25310:
253 = (2 × 102) + (5 × 101) + (3×100)
Common Number Systems
Number System Base (Radix) Digits Used Example
Decimal 10 0–9 257₁₀
Binary 2 0, 1 1011₂
Octal 8 0–7 745₈
Hexadecimal 16 0–9, A–F 3A₁₆
Applications in Digital Systems
• Decimal (Base-10): Used in human computation and day-to-day arithmetic.
• Binary (Base-2): Core of digital systems, representing two states: ON (1) and OFF (0).
• Octal (Base-8): Simplifies binary grouping, often used in early computers.
• Hexadecimal (Base-16): Compact representation of binary, widely used in programming
and memory addressing.
� Did You Know?
The word “digit” comes from the Latin digitus, meaning “finger.” Early counting was done
using fingers, leading to our base-10 system.
The Decimal (Base-10) System
The decimal system is the most familiar number system, used universally in everyday life. It has
a base of 10, which means it uses ten digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Each position in a decimal number has a place value that is a power of 10.
For example:
372510 = (3×103) + (7×102) + (2×101) + (5×100)
= 3000 + 700 + 20 + 5
Characteristics of the Decimal System
• Base = 10
• Digits = 0–9
• Place value increases from right to left in powers of 10
• The decimal point separates whole numbers from fractions
Decimal Fractions
Numbers can also have fractional parts, represented to the right of the decimal point.
Example:
25.347 = (2×101) + (5×100) + (3×10−1) + (4×10−2) + (7×10−3)
This expansion allows exact representation of many real-world quantities.
Real-World Applications
• Commerce & Finance: Currency, accounting, taxes.
• Measurements: Length, weight, temperature, etc.
• Everyday Life: Phone numbers, prices, statistics.
� Did You Know?
The decimal system originated in ancient India, where the concept of zero as a digit was first
formalized. This revolutionary idea spread to the Arab world, then to Europe, forming the basis
of modern mathematics.
The Binary System in Detail
The Binary (Base-2) System
The binary system uses only two digits:
0, 1
Because it directly represents the two states of digital devices - ON (1) and OFF (0) - it is the
foundation of all modern computing and logic circuits.
Each digit in a binary number is called a bit (binary digit). Groups of bits form larger units:
• Nibble: 4 bits
• Byte: 8 bits
• Word: Typically 16, 32, or 64 bits (depending on processor architecture)
Place Value in Binary
Just like decimal uses powers of 10, binary uses powers of 2.
Example:
10112 = (1×23) + (0×22) + (1×21) + (1×20)
10112 = 8 + 0 + 2 + 1 = 1110
3. Binary Fractions
Fractions are also possible in binary using negative powers of 2.
Example:
0.1012 = (1×2−1) + (0×2−2) + (1×2−3)
0.1012 = 0.5 + 0 + 0.125 = 0.62510
Real-World Applications
• Digital Electronics: Logic gates, circuits, processors
• Data Storage: Hard drives, memory, flash
• Networking: IP addresses, data packets
• Programming: Boolean logic, control structures
� Did You Know?
The first binary-based computing machine was built in the 1930s by Konrad Zuse, a German
engineer. His computer, the Z1, used binary arithmetic long before modern digital computers were
developed.
The Octal System in Detail
The Octal (Base-8) System
The octal system uses eight digits:
0, 1, 2, 3, 4, 5, 6, 7
Each position in an octal number represents a power of 8.
Example:
7458 = (7×82) + (4×81) + (5×80)
7458 = (7×64) + (4×8) + (5×1) = 448 + 32 + 5 = 48510
Place Value in Octal
• Rightmost digit → 80 = 1
• Next digit → 81 = 8
• Next digit → 82 = 64
• Next digit → 83 = 512, and so on.
Conversion between Octal and Binary
Octal is often used as a shorthand for binary because each octal digit corresponds to exactly
three binary digits (bits).
Example:
7458 = 111 100 1012
Explanation:
• 7 = 111
• 4 = 100
• 5 = 101
So, 7458 = 1111001012.
Real-World Applications
• Early Computers: Many systems used octal to simplify binary representation.
• Digital Electronics: Still used in some microprocessor instruction sets.
• Permissions in Unix/Linux Systems: File permissions (e.g., chmod 755) are represented
in octal.
� Did You Know?
Before hexadecimal became the standard, early programmers used octal notation to work with
machine code. This was especially common in the 1960s with PDP (Programmed Data Processor)
computers.
The Hexadecimal System in Detail
The Hexadecimal (Base-16) System
The hexadecimal system (hex) uses sixteen digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Where:
• A=10,
• B=11,
• C=12,
• D=13,
• E=14,
• F=15.
Place Value in Hexadecimal
Each digit represents a power of 16.
Example:
3A716 = (3×162) + (A×161) + (7×160)
3A716 = (3×256) + (10×16) + (7×1) = 768 + 160 + 7 = 93510
Conversion between Hexadecimal and Binary
Hexadecimal is very convenient because each hex digit corresponds to exactly four binary
digits (bits).
Example:
3A716 = 0011 1010 01112
Explanation:
• 3 = 0011
• A = 1010
• 7 = 0111
So, 3A716 = 0011101001112.
Real-World Applications
• Memory Addressing: Hex is used to represent memory locations in computers.
• Colors in Web Design: Hex codes represent RGB colors (e.g., #FF5733).
• Machine Code: Assembly language often uses hex to simplify binary instructions.
� Did You Know?
The prefix “0x” is commonly used in programming to indicate a hexadecimal number. For
example, 0x1F means 1F16 = 3110.
Comparison of Number Systems
To better understand the relationship between decimal, binary, octal, and hexadecimal, let’s
compare them side by side.
Comparative Table of Number Systems
Decimal Binary Octal Hexadecimal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
2. Key Relationships
• Binary to Octal: Group bits in sets of 3.
• Binary to Hex: Group bits in sets of 4.
• Octal ↔ Hex: Convert via binary as an intermediate step.
Example:
10101102 = 1268 = 5616
Practical Use
• Decimal: Everyday human calculations.
• Binary: Machine-level operations.
• Octal: Historical use in programming, still used in Linux permissions.
• Hexadecimal: Compact representation for programmers and hardware engineers.
� Did You Know?
The Intel 4004 microprocessor (1971), the world’s first commercially available microprocessor,
had a 12-bit instruction word. Programmers often used octal and hexadecimal to write
machine instructions more compactly.
Number Base Conversion Methods
Understanding how to convert between number systems is fundamental in digital logic design.
Below are systematic methods with worked examples.
Decimal to Binary Conversion
Method: Repeated division by 2.
• Record the remainders.
• Read from bottom to top.
Example: Convert 4510 to binary.
45 ÷ 2 = 22 remainder 1
22 ÷ 2 = 11 remainder 0
11 ÷ 2 = 5 remainder 1
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
Reading upward → 4510=1011012
Binary to Decimal Conversion
Method: Multiply each bit by 2n and add.
Example: Convert 110012.
= (1×24) + (1×23) + (0×22) + (0×21) + (1×20)
= 16 + 8 + 0 + 0 + 1 = 2510
Decimal to Octal Conversion
Method: Repeated division by 8.
Example: Convert 34510.
345 ÷ 8 = 43 remainder 1
43 ÷ 8 = 5 remainder 3
5 ÷ 8 = 0 remainder 5
So, 34510 = 5318
Decimal to Hexadecimal Conversion
Method: Repeated division by 16.
Example: Convert 93510.
935 ÷ 16 = 58 remainder 7
58 ÷ 16 = 3 remainder 10
3÷16 = 0 remainder 3
So, 93510 = 3A716.
� Did You Know?
When converting fractions, multiply repeatedly by the base instead of dividing. For example,
0.62510 → 0.1012.
Conversion of Fractions Between Bases
Whole numbers are straightforward, but fractions require a slightly different approach when
converting between number systems.
Decimal Fraction to Binary
Method: Multiply repeatedly by 2.
• The integer part after each multiplication becomes the next binary digit.
• Stop when the fraction becomes 0 or reaches desired precision.
Example: Convert 0.62510 to binary.
0.625 × 2 = 1.25 ⇒ 1
0.25 × 2 = 0.5 ⇒ 0
0.5 × 2 = 1.0 ⇒ 1
Reading results: 0.1012.
Decimal Fraction to Octal
Method: Multiply repeatedly by 8.
Example: Convert 0.310.
0.3 × 8 = 2.4 ⇒ 2
0.4 × 8 = 3.2 ⇒ 3
0.2 × 8 = 1.6 ⇒ 1
0.6 × 8 = 4.8 ⇒ 4
So, 0.310 ≈ 0.23148.
Decimal Fraction to Hexadecimal
Method: Multiply repeatedly by 16.
Example: Convert 0.812510.
0.8125 × 16 = 13.0 ⇒ D.
Binary Fraction to Decimal
Method: Multiply each digit by 2−n.
Example: Convert 0.1012.
(1×2−1) + (0×2−2) + (1×2−3) = 0.5 + 0 + 0.125 = 0.62510
� Illustration (Line Diagram):
Imagine a fraction bar showing binary place values:
• 2−1 = 0.5
• 2−2 = 0.25
• 2−3 = 0.125
Each bit "fills" a fraction of the unit.
� Did You Know?
Some fractions can never be represented exactly in binary (like 0.110). Computers store them
approximately, which is why rounding errors occur in calculations.
Binary Arithmetic
Digital circuits perform operations directly in binary. Understanding binary arithmetic is
essential for designing adders, subtractors, and other logic components.
Binary Addition
Rules of Addition:
A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Example: 10112 + 11012
1011
+ 1101
11000
So, result = 110002 = 2410.
Binary Subtraction
Rules of Subtraction:
A B Difference Borrow
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
Example: 100102 − 11012
10010
+ 1101
0101
So, result = 1012 = 510
Binary Multiplication
Rules: Similar to decimal multiplication, except only 0s and 1s.
Example: 1012 × 112.
101
x 11
101 (101 × 1)
+1010 (101 × 1, shifted)
1111
So, result = 1012 × 112 = 11112 = 1510.
Binary Division
Method: Similar to long division in decimal.
Example: 101102 ÷ 112.
00111__
11 ∕ 10110
11
101
11
100
11
1
So, result = 101102 ÷ 112 = 1112 r 1 = 22 ÷ 3 = 7 r 1
� Did You Know?
Binary division is rarely done directly in hardware. Instead, circuits often use repeated
subtraction or special algorithms (like restoring division) implemented in microprocessors.
Complements in Binary Arithmetic
Complements are useful in simplifying subtraction and in designing arithmetic circuits. Computers
typically use 1’s complement or 2’s complement to represent negative numbers.
1’s Complement
• Definition: Invert (flip) every bit of the binary number.
• Example:
101012 ⇒ 010102
Use in Subtraction:
To compute A − B take the 1’s complement of B and add it to A. If there’s a carry, add it back
(end-around carry).
Example: 10102 − 10012
1. B = 10012, 1’s complement = 01102.
2. Add: 10102 + 01102 = 10000.
3. End-around carry → 0001.
4. Final answer = 00012.
2’s Complement
• Definition: Take the 1’s complement, then add 1.
• Example:
101012 ⇒ 010102 + 1 = 010112 = 010112
Use in Subtraction:
To compute A – B, add A + (2’s complement of B). Ignore the final carry.
Example: 10102 − 10012
1. B = 10012, 2’s complement = 01112.
2. Add: 1010 + 0111 = 10001.
3. Discard extra carry.
4. Result = 00012.
Why Use Complements?
• Simplifies hardware: only an adder is needed (no separate subtraction circuit).
• 2’s complement is the standard in modern computers because it avoids the ambiguity of
having “+0” and “-0” (a problem in 1’s complement).
� Illustration (Line Drawing Idea):
A diagram showing:
• A binary number.
• Its 1’s complement (flipped bits).
• Its 2’s complement (flipped bits + 1).
� Did You Know?
Early computers like the IBM 7090 used 1’s complement, while nearly all modern systems (x86,
ARM, RISC-V) use 2’s complement for negative integers.
Signed Number Representations
In digital systems, numbers can be positive or negative. To represent both, special schemes are
used. The three main methods are Sign-Magnitude, 1’s Complement, and 2’s Complement.
Sign-Magnitude Representation
• The most significant bit (MSB) is the sign bit:
o 0 → Positive
o 1 → Negative
• Remaining bits represent the magnitude (absolute value).
Example (4-bit system):
Decimal Binary (Sign-Magnitude)
+5 0101
–5 1101
� Limitation: Two representations of zero exist (+0 = 0000, –0 = 1000).
1’s Complement Representation
• Negative numbers = bitwise inversion of the positive number.
• Example (4-bit system):
Decimal Binary (1’s Complement)
+5 0101
–5 1010
� Limitation: Still has +0 (0000) and –0 (1111).
2’s Complement Representation
• Negative numbers = 1’s complement + 1.
• Example (4-bit system):
Decimal Binary (2’s Complement)
+5 0101
–5 1011
� Advantage:
• Only one zero (0000).
• Arithmetic is simpler → one adder circuit handles both addition and subtraction.
Comparison of the Three Systems
Feature Sign-Magnitude 1’s Complement 2’s Complement
Zero Representations +0, –0 +0, –0 Only one zero
Hardware Simplicity Moderate Moderate High (preferred)
Range (4-bit system) –7 to +7 –7 to +7 –8 to +7
� Illustration (Line Drawing Idea):
A number line from –8 to +7 showing how each representation places values differently.
� Did You Know?
In floating-point standards (IEEE 754), negative numbers are not represented using 2’s
complement but through a sign bit + biased exponent + fraction (mantissa) format.
Binary Codes
Binary codes are methods of representing numbers, characters, or symbols using binary digits (0s
and 1s). They are essential in digital systems, communication, and computer memory storage.
We will focus on three important types: BCD (Binary-Coded Decimal), Excess-3, and Gray
Code.
Binary-Coded Decimal (BCD)
• Represents decimal digits (0–9) using 4-bit binary equivalents.
• Example:
o Decimal 25 → 0010 0101 in BCD (not 11001).
Decimal BCD Code
0 0000
1 0001
2 0010
… …
9 1001
� Advantage: Easy for digital systems to handle decimal numbers.
� Limitation: Not space-efficient (only 10 out of 16 combinations are used).
Excess-3 Code
• Derived from BCD by adding 3 (0011) to each digit.
• Used in error detection and simplifies arithmetic in some cases.
Decimal BCD Excess-3
0 0000 0011
1 0001 0100
2 0010 0101
… … …
9 1001 1100
3. Gray Code
• Also called Reflected Binary Code.
• Only one-bit changes between successive numbers.
• Useful in minimizing errors in mechanical switches, encoders, and communication.
Decimal Binary Gray Code
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
� Illustration (Line Drawing Idea):
• A 4-bit Gray code wheel showing how only one bit changes at each step.
• Comparison diagram of Binary vs BCD vs Excess-3.
� Did You Know?
ray code was named after Frank Gray, who patented it in 1953. It’s still widely used in rotary
encoders to reduce reading errors caused by mechanical imperfections.
Character Codes – ASCII and Unicode
Numbers are not the only things computers represent. They must also handle letters, symbols,
and special characters. To achieve this, character codes like ASCII and Unicode are used.
ASCII (American Standard Code for Information Interchange)
• Developed in the 1960s, ASCII uses 7 bits to represent 128 characters.
• Includes:
o Uppercase and lowercase letters (A–Z, a–z)
o Numbers (0–9)
o Punctuation symbols (!, ?, +, etc.)
o Control characters (Enter, Tab, Backspace, etc.)
Character ASCII (Binary) ASCII (Decimal)
A 1000001 65
B 1000010 66
a 1100001 97
0 0110000 48
� Advantage: Simple and widely used.
� Limitation: Only supports English characters.
Extended ASCII
• Uses 8 bits → 256 characters.
• Adds symbols, accented letters (é, ñ, ü), and line-drawing characters.
• Common in early PC systems.
Unicode
• Designed to cover all writing systems worldwide.
• Uses variable-length encoding:
o UTF-8 (1–4 bytes per character)
o UTF-16 (2 or 4 bytes)
o UTF-32 (4 bytes)
• Supports over 143,000 characters including:
o Latin, Greek, Cyrillic alphabets
o Chinese, Japanese, Korean scripts
o Emojis (� �, �, �)
Character Unicode Code Point UTF-8 Encoding
A U+0041 01000001
é U+00E9 11000011 10101001
� U+1F60A 11110000 10011111 10011000 10101010
� Illustration (Line Drawing Idea):
• A timeline chart showing evolution from ASCII → Extended ASCII → Unicode.
• Sample text comparison: "Hello" in ASCII vs "こんにちは" in Unicode.
Char Unicode (U+xxxx) UTF-16 Hex Binary (16-bit)
H U+0048 0048 00000000 01001000
e U+0065 0065 00000000 01100101
l U+006C 006C 00000000 01101100
l U+006C 006C 00000000 01101100
o U+006F 006F 00000000 01101111
� Did You Know?
The heart emoji � (U+2764) is one of the most frequently used Unicode characters worldwide,
showing how digital codes have evolved beyond numbers and letters to include emotions!
Error Detection and Correction Codes
When digital data is stored or transmitted, it may become corrupted due to noise, interference,
or hardware faults. To ensure reliability, systems use error detection and correction (EDC)
codes.
Parity Bit
• Simplest error-detection method.
• A parity bit is added to make the total number of 1s either even (even parity) or odd
(odd parity).
Example:
• Data: 1010 110
• Even Parity → Add 1 → 1010 1101
• Odd Parity → Add 0 → 1010 1100.
� Easy to implement.
� Can only detect single-bit errors, not correct them.
Checksums
• Data is divided into blocks.
• A simple sum of all blocks is sent along with data.
• The receiver recomputes the sum → if mismatch → error detected.
� Useful in network protocols.
� Weak against certain error patterns.
3. Cyclic Redundancy Check (CRC)
Powerful error-detection method using polynomial division.
• Example:
o Data: 1101
o Generator: 1011
o Remainder (CRC) is appended to data.
• Used in Ethernet, Wi-Fi, hard disks.
� Detects burst errors (multiple bits).
� Still cannot correct errors.
Hamming Code
• Developed by Richard Hamming (1950).
• Adds redundant parity bits at specific positions (1, 2, 4, 8…).
• Can detect and correct single-bit errors.
Example (4-bit data → 7-bit Hamming Code):
• Data: 1011
• Encoded: 1011011 (with parity bits added).
� Enables Single Error Correction, Double Error Detection (SEC-DED).
� Illustration (Line Drawing Idea):
• Diagram of Hamming (7,4) code with parity bit positions (P1, P2, P4).
• Flowchart showing how parity bits detect error location.
� Did You Know?
The Voyager spacecraft, launched in 1977 and still transmitting data billions of kilometers
away, relies on error-correcting codes to ensure messages reach Earth without corruption.
End of Module Questions:
1. Why is binary considered the foundation of digital electronics?
2. Differentiate between decimal and binary systems in terms of base and digits used.
3. Why is octal often used as a shorthand for binary?
4. How does hexadecimal simplify working with binary numbers?
5. What is the significance of Gray Code in error minimization?
6. Why is ASCII widely used in computer systems?
7. What is the advantage of Unicode over ASCII?
8. Why do we use BCD when binary is already available?
9. Why is hexadecimal widely used in programming and debugging?
10. How does the choice of number system affect data storage efficiency?
End of Module Problems:
1. Convert 15610 to binary, octal, and hexadecimal.
2. Convert 11010112 to decimal.
3. Convert 101011012 to octal and hexadecimal.
4. Convert 73 to binary.
5. Convert 3E16 to decimal and binary.
6. Convert 245 to hexadecimal.
7. Convert 57 into BCD.
8. Convert 1001012100101_21001012 into BCD.
9. Convert 255 into binary and hexadecimal.
10. Convert 10110012 into Gray Code.
11. Perform: 10112 + 11012.
12. Perform: 111012 + 100112.
13. Perform: 1011012 − 11012.
14. Perform: 110012−1010211001_2 - 1010_2110012−10102.
15. Multiply: 1012 × 112.
16. Multiply: 1102 × 1012.
17. Divide: 110102 ÷ 1012.
18. Perform subtraction: 1001102 − 111012.
19. Add 111111112 + 12. (What happens?)
20. Convert 89 to binary and show step-by-step division method.
21. Encode decimal 248 into BCD.
22. Convert BCD 0101 1001 to decimal.
23. Convert Gray Code 1011 to binary.
24. Convert Gray Code 1110 to binary.
25. What is the ASCII code for character ‘A’? (Binary + Decimal + Hex).
26. What is the ASCII code for character ‘z’?
27. Convert the string “HI” into ASCII binary representation.
28. Convert ASCII decimal 66 into character form.
29. Convert binary 01001000 01001001 into text.
30. Convert Unicode U+0041 into decimal and binary.