Computer Science Book (2)
Computer Science Book (2)
Time
Generation Technology Used Key Features
Period
Input Unit Takes user input and converts it into binary data Keyboard, Mouse, Scanner
Memory
Stores data temporarily or permanently RAM, ROM, Hard Drive
Unit
Control
Directs operations of the processor Part of CPU
Unit
Output Unit Converts binary data to human-readable form Monitor, Printer, Speaker
1
1.3 Number Systems and Conversions
Number systems are methods for representing numbers. The most common systems used in computing
are: - Binary (Base-2) - Octal (Base-8) - Decimal (Base-10) - Hexadecimal (Base-16)
Each of these has a unique way to represent integers and fractional values.
Decimal to Others
Decimal to Binary
Integer Part: - Divide by 2 and record the remainder. - Reverse the remainders. - Example: 25 → 11001
Fractional Part: - Multiply by 2 and take the integer part. - Continue with the fractional part. - Example:
0.625 - 0.625 × 2 = 1.25 → 1 - 0.25 × 2 = 0.5 → 0 - 0.5 × 2 = 1.0 → 1 - Result: 0.101
Decimal to Octal
Fractional Part: Multiply by 8. - Example: 0.8125 - 0.8125 × 8 = 6.5 → 6 - 0.5 × 8 = 4.0 → 4 - Result: 0.64
Decimal to Hexadecimal
Fractional Part: Multiply by 16. - Example: 0.6875 - 0.6875 × 16 = 11.0 → B - Result: 0.B
Binary to Others
Binary to Decimal
Binary to Octal
• Group in 3 bits.
• Example: 110101.011
• 110 101 . 011 → Octal: 65.3
2
Binary to Hexadecimal
• Group in 4 bits.
• Example: 10110111 → 1011 0111 → B7
Octal to Others
Octal to Decimal
Fractional Example: - Convert 17.52 (Octal) to Decimal - Integer part: 1×8¹ + 7×8⁰ = 8 + 7 = 15 - Fraction
part: 5×8⁻¹ + 2×8⁻² = 0.625 + 0.03125 = 0.65625 - Result: 15.65625
Octal to Binary
Fractional Example: - Convert 7.4 (Octal) to Binary: - 7 = 111 - .4 → Binary of 4 = 100 (in octal, 4 is a single
digit) - So, 7.4 → 111.100 in binary - Result: 111.100
Octal to Hexadecimal
Hexadecimal to Others
3
• B = 11 → 11 × 16⁻¹ = 11 ÷ 16 = 0.6875
• Total = 3 + 0.6875 = 3.6875
Example: Convert 3.B (Hex) to Octal - 3 = 0011, B = 1011 → Binary = 0011.1011 - Group: 000 011 . 101 100
→ Octal: 3.54 - Final Answer: 3.B₁₆ = 3.54₈
Hex to Binary
Hex to Decimal
Hexadecimal to Octal
Integer Example: - A2 (Hex) - Hex to Binary: A = 1010, 2 = 0010 → 10100010 - Group in 3s: 010 100 010 →
Octal: 2 4 2 → Answer: 242
Fractional Example: - Convert 2.F (Hex) to Octal - 2 = 0010, F = 1111 → Binary: 0010.1111 - Group: 000 010 .
111 100 → Octal: 2.74 - Result: 2.74 - Step 2: Group binary into 3-bit segments from right to left. - Step 3:
Convert each group to octal. - Example: A2 (Hex) - Hex to Binary: A = 1010, 2 = 0010 → 10100010 - Group in
3s: 010 100 010 → Octal: 2 4 2 - Answer: 242### Floating Point Representation
A floating point number represents real numbers using scientific notation in binary format.
Is the Bias Always 127? No. The bias value depends on the precision format being used in IEEE 754
standard:
4
This bias helps in representing both positive and negative exponents without using a sign bit for the
exponent itself.
Why Add 127 (Bias) to the Exponent? In IEEE 754 format, the exponent is stored using a technique called
"biased exponent." This means: - Instead of storing negative exponents directly (which would require a
separate sign), we add a constant value (called bias) to the actual exponent. - For 32-bit IEEE 754, the bias is
127. - So, an actual exponent of 0 is stored as 127, exponent 1 as 128, exponent -1 as 126, etc. - This
simplifies hardware implementation and comparison of floating point numbers.
IEEE 754 Single Precision Format (32-bit): - 1 bit for Sign (0 = positive, 1 = negative) - 8 bits for Exponent
(with a bias of 127) - 23 bits for Mantissa (fractional part after the leading 1)
Steps: 1. Convert the number to binary. 2. Normalize it (shift to make only one non-zero digit before
decimal). 3. Determine sign bit (0 or 1). 4. Calculate exponent and add bias. 5. Write the mantissa.
Example: Represent 5.75 in IEEE 754: - Binary of 5.75 = 101.11 - Normalized: 1.0111 × 2² - Sign = 0 (positive)
- Exponent = 2 + 127 = 129 → 10000001 - Mantissa = 01110000000000000000000 - Result: 0 10000001
01110000000000000000000
Operations:
Complements:
• 1’s Complement:
• Flip all bits (0↔1)
• 2’s Complement:
5
1.5 Codes
1. BCD (Binary-Coded Decimal): - Each digit of a decimal number is represented by its 4-bit binary
equivalent. - Example: - Decimal 259 → BCD: 0010 0101 1001 - Used in digital clocks, calculators.
2. Excess-3 (XS-3): - A self-complementary code used for decimal digits. - It adds 3 to each decimal digit,
then converts to binary. - Example: - Decimal 4 → 4 + 3 = 7 → Binary: 0111
3. Gray Code: - Gray Code is a binary numbering system where only one bit changes at a time between
two successive numbers. - This helps prevent errors in digital electronics, especially during signal transition
when multiple bits changing simultaneously might cause glitches.
• When binary numbers count up (e.g., from 3 (011) to 4 (100)), more than one bit changes at once.
• This can confuse digital circuits if bits change at slightly different times.
• Gray Code prevents this by ensuring only one bit flips at a time.
• Binary = 1 0 1 1
• Step 1: First bit = 1
• Step 2: 1 ⊕ 0 = 1
• Step 3: 0 ⊕ 1 = 1
• Step 4: 1 ⊕ 1 = 0
• Gray Code = 1 1 1 0
• Binary = 1 1 0 1
• Step 1: First bit = 1
• Step 2: 1 ⊕ 1 = 0
• Step 3: 1 ⊕ 0 = 1
• Step 4: 0 ⊕ 1 = 1
• Gray Code = 1 0 1 1
To convert Gray Code back to Binary: 1. Keep the first bit (MSB) the same. 2. For each next bit: - If Gray bit =
0 → Copy previous binary bit - If Gray bit = 1 → Invert previous binary bit
6
Example: Convert Gray Code 1011 to Binary
• Gray = 1 0 1 1
• Step 1: First bit = 1
• Step 2: 0 → Copy = 1
• Step 3: 1 → Invert = 0
• Step 4: 1 → Invert = 1
• Binary = 1 1 0 1
• Rotary Encoders
• Karnaugh Maps (to reduce logic expressions)
• Analog-to-Digital Conversion
4. ASCII (American Standard Code for Information Interchange): - 7-bit code to represent text
characters. - Example: - A → 1000001 (65 in decimal), a → 1100001 (97 in decimal) - Used in keyboards, files,
text data.
5. EBCDIC (Extended Binary Coded Decimal Interchange Code): - 8-bit code used in IBM mainframes. -
Different from ASCII. - Example: - A → 11000001
Comparison Table:
Logic gates are the fundamental building blocks of digital circuits. They operate using binary input values (0
and 1) and produce binary output based on a logical operation.
7
Below are the basic logic gates with their symbol descriptions, Boolean expressions, and compact truth
tables in list form:
AND Gate AND Gate - - Boolean Expression: Y = A · B - Truth Table: - A=0, B=0 → Y=0 - A=0, B=1 → Y=0 -
A=1, B=0 → Y=0 - A=1, B=1 → Y=1
OR Gate OR Gate - - Boolean Expression: Y = A + B - Truth Table: - A=0, B=0 → Y=0 - A=0, B=1 → Y=1 - A=1,
B=0 → Y=1 - A=1, B=1 → Y=1
NOT Gate NOT Gate - - Boolean Expression: Y = ¬A - Truth Table: - A=0 → Y=1 - A=1 → Y=0
NAND Gate NAND Gate - - Boolean Expression: Y = ¬(A · B) - Truth Table: - A=0, B=0 → Y=1 - A=0, B=1 →
Y=1 - A=1, B=0 → Y=1 - A=1, B=1 → Y=0
NOR Gate NOR Gate - - Boolean Expression: Y = ¬(A + B) - Truth Table: - A=0, B=0 → Y=1 - A=0, B=1 → Y=0 -
A=1, B=0 → Y=0 - A=1, B=1 → Y=0
XOR Gate (Exclusive OR) XOR Gate - - Boolean Expression: Y = A ⊕ B - Truth Table: - A=0, B=0 → Y=0 - A=0,
B=1 → Y=1 - A=1, B=0 → Y=1 - A=1, B=1 → Y=0
XNOR Gate (Exclusive NOR) XNOR Gate - - Boolean Expression: Y = ¬(A ⊕ B) - Truth Table: - A=0, B=0 →
Y=1 - A=0, B=1 → Y=0 - A=1, B=0 → Y=0 - A=1, B=1 → Y=1
Each gate can be constructed using electronic components like diodes and transistors and is essential in
designing circuits.
Boolean algebra deals with expressions involving binary variables and logic operations.
Example: - Expression: Y = A·(B + ¬C) - Truth table involves listing all combinations of inputs A, B, and C, and
computing Y for each.
A B C ¬C B + ¬C A·(B + ¬C) = Y
0 0 0 1 1 0
0 0 1 0 0 0
1 1 0 1 1 1
1 1 1 0 1 1
8
(Next: Boolean Laws, Expression Simplification, Karnaugh Maps, Adders/Subtractors...)