By the end of this chapter, you will be able to:
Mastering these skills will help you understand how computers process data, making you a stronger and more confident technician in the digital world.
Computer arithmetic and logic form the foundation of all computing processes, enabling computers to perform calculations, make decisions, and process data efficiently. Mastery of number systems, their operations, and conversions is essential for computer scientists, especially in Kenya's growing software development and data science industries. This chapter focuses on the key number systems used in computer architecture, how arithmetic operations are performed within these systems, and how to convert numbers between them for effective computation and programming.
Number systems are the mathematical frameworks computers use to represent, store, and manipulate data. Understanding these systems is crucial for tasks such as programming, circuit design, and algorithm development in Kenya’s IT sector. This section covers the types of number systems, operations performed on them, and conversion techniques between different systems.
Number systems define the base or radix used to represent numbers. The most common types in computer science are binary, octal, decimal, and hexadecimal. Each system uses a unique set of digits and positional values to express numbers.
The binary system uses base 2 and digits 0 and 1. It is the fundamental language of computers because digital circuits have two states: ON and OFF.
The octal system uses base 8 and digits 0 to 7.
The decimal system uses base 10 and digits 0 to 9.
The hexadecimal system uses base 16 and digits 0 to 9 plus A to F.
Example 1: Convert the decimal number 13 to binary.
Given: Decimal number = 13
Divide by 2 repeatedly, recording remainders:
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Reading remainders from bottom to top: 1101
Answer: Binary 1101
Example 2: Convert binary 101101 to octal.
Group binary digits in sets of 3 from right: 101 101
Convert each group:
101 = 5
101 = 5
Answer: Octal 55
Example 3: Convert hexadecimal 2F to decimal.
2F hex = (2 × 16) + (15 × 1) = 32 + 15 = 47
Answer: Decimal 47
Arithmetic operations such as addition, subtraction, multiplication, and division have distinct methods in different number systems. Mastering these operations is essential for algorithms and low-level programming in Kenya’s software development industry.
Binary addition follows rules similar to decimal addition but with base 2.
Binary subtraction uses borrow similar to decimal subtraction.
Example: Subtract binary 1010 from 1101.
Given: \(1101_2 - 1010_2\)
Step 1: Align the numbers:
\( \begin{array}{cccc} & 1 & 1 & 0 & 1 \\ - & 1 & 0 & 1 & 0 \\ \end{array} \)
Step 2: Subtract bit by bit from right, handling borrows:
Final result: \(0011_2\)
Answer: \(11_2\) (decimal 3)
Binary multiplication is like decimal multiplication but simpler.
Example: Multiply binary 101 by 11.
Given: \(101_2 \times 11_2\)
Step 1: Write 11 as two bits: \(11_2 = 3_{10}\)
Multiply each bit:
Step 2: Add partial products:
\( \begin{array}{cccc} & & 1 & 0 & 1 \\ + & 1 & 0 & 1 & 0 \\ \hline & 1 & 1 & 1 & 1 \\ \end{array} \)
Answer: \(1111_2\) (decimal 15)
Binary division involves repeated subtraction of divisor shifted appropriately.
Example: Divide binary 1101 by 10.
Given: \(1101_2 \div 10_2\)
Step 1: Convert to decimal for verification: \(1101_2 = 13_{10}\), \(10_2 = 2_{10}\)
Step 2: Binary long division:
Quotient: \(110_2\) (decimal 6), Remainder: \(1_2\)
Answer: Quotient = \(110_2\), Remainder = \(1_2\)
Example 1: Add binary numbers 1101 and 1011.
Given: 1101 + 1011
Add bit by bit from right:
1 + 1 = 10 (write 0 carry 1)
0 + 1 + carry 1 = 10 (write 0 carry 1)
1 + 0 + carry 1 = 10 (write 0 carry 1)
1 + 1 + carry 1 = 11 (write 1 carry 1)
Write carry 1 to leftmost position.
Result: 11000
Answer: Binary 11000
Example 2: Subtract binary 1010 from 1101.
Given: 1101 - 1010
Subtract bit by bit:
1 - 0 = 1
0 - 1 (borrow 1) = 1
0 - 0 = 0
1 - 1 = 0
Result: 0011
Answer: Binary 11
Example 3: Multiply binary 101 by 11.
Given: 101 × 11
101 × 1 = 101
101 × 1 (shifted left 1) = 1010
Add:
0101
+1010
=1111
Answer: Binary 1111
Converting numbers accurately between decimal, binary, octal, and hexadecimal is vital for programming, debugging, and data representation in Kenyan IT environments.
Use successive division by 2, recording remainders.
Multiply each bit by \(2^{position}\) and sum all.
Group binary digits into sets of 3 (octal) or 4 (hexadecimal) starting from right, then convert each group to respective digit.
Convert each octal or hex digit to its binary equivalent.
Example 1: Convert decimal 45 to binary.
Divide by 2 repeatedly:
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
Read remainders bottom-up: 101101
Answer: Binary 101101
Example 2: Convert binary 110101 to decimal.
Calculate:
\(1 \times 2^5 = 32\)
\(1 \times 2^4 = 16\)
\(0 \times 2^3 = 0\)
\(1 \times 2^2 = 4\)
\(0 \times 2^1 = 0\)
\(1 \times 2^0 = 1\)
Sum: 32 + 16 + 0 + 4 + 0 + 1 = 53
Answer: Decimal 53
Example 3: Convert binary 101110111 to hexadecimal.
Group into 4 bits from right: 0001 0111 0111
Convert each group:
0001 = 1
0111 = 7
0111 = 7
Answer: Hexadecimal 177
Create a free account to open more of this chapter.
Free: practical guides, quick cards, workplace scenarios and more.
Create a free accountThis chapter explored the fundamentals of computer arithmetic and logic starting with number systems, including their types, basic operations, and methods for converting between different systems. It then examined IEEE-based standards for representing integers and floating-point numbers, which are essential for consistent data processing in computers. The chapter detailed arithmetic operations such as addition, subtraction, and multiplication for both integer and floating-point formats, highlighting their differences and computational approaches. Logic operators including OR, AND, NAND, NOR, and NOT were introduced, explaining their roles in binary logic manipulation. Further, the chapter covered logic operations corresponding to arithmetic functions like addition, multiplication, subtraction, and division within logical contexts. Finally, it discussed various ways to represent logic operations, focusing on truth tables, Karnaugh maps for simplification, and the implementation of logic gates in digital circuits. Together, these topics provide a comprehensive understanding of how computers perform arithmetic and logical functions at the hardware level.
Convert the decimal number \(45\) to its binary equivalent. (2 marks)
Add the binary numbers \(1011_2\) and \(1101_2\). Provide the result in binary. (3 marks)
Type: Individual
| Tools & Equipment | Materials |
|---|---|
| A working computer | Plain paper |
| Scientific calculator | |
| Pen |
| S/N | Item | Quantity |
|---|---|---|
| 1 | A working computer | 1 Pc per Candidate |
| 2 | Scientific calculator | 1 Pc per Candidate |
| 3 | Plain paper | 5 Sheets per Candidate |
| 4 | Pen | 1 Pc per Candidate |
| Items to be Evaluated | Marks Available | Marks Obtained | Comments |
|---|---|---|---|
| TASK 1: Perform number system conversions | |||
| Wore personal protective equipment (if applicable) (Award 1 mark for wearing PPE or zero) | 1 | ||
| Converted decimal 3457 to binary, octal, and hexadecimal correctly (Award 2 marks each for correct binary, octal, and hexadecimal conversions; 2 marks for correct method shown) | 8 | ||
| Converted binary 1101101 to decimal, octal, and hexadecimal correctly (Award 2 marks each for correct decimal, octal, and hexadecimal conversions; 2 marks for correct method shown) | 8 | ||
| Converted octal 725 to binary, decimal, and hexadecimal correctly (Award 2 marks each for correct binary, decimal, and hexadecimal conversions; 2 marks for correct method shown) | 8 | ||
| Converted hexadecimal 1F4A to binary, decimal, and octal correctly (Award 2 marks each for correct binary, decimal, and octal conversions; 2 marks for correct method shown) | 8 | ||
| Presented all conversions in a clear, well-formatted table (Award up to 7 marks for clarity, completeness, and neatness of presentation) | 7 | ||
| Sub-Total | 40 | ||
| PRODUCT CHECKLIST | |||
| All converted numbers are accurate and match expected values (Award 10 marks for 100% accuracy; partial credit for minor errors) | 10 | ||
| Sub-Total | 10 | ||
| GRAND TOTAL | 50 | ||
Type: Individual
| Tools & Equipment | Materials |
|---|---|
| Scientific calculator with binary mode | Plain paper |
| Computer with binary arithmetic software | Pen or pencil |
| S/N | Item | Quantity |
|---|---|---|
| 1 | Scientific calculator with binary mode | 1 Pc per Candidate |
| 2 | Computer with binary arithmetic software (e.g., a binary calculator or programming IDE) | 1 Pc per Candidate |
| 3 | Plain paper | 5 Sheets per Candidate |
| 4 | Pen or pencil | 1 Pc per Candidate |
| Items to be Evaluated | Marks Available | Marks Obtained | Comments |
|---|---|---|---|
| TASK 1: Integer Binary Addition | |||
| Wore personal protective equipment (if applicable) (Award 1 mark or zero) | 1 | ||
| Correctly converted decimal integers to 8-bit binary (if given decimal inputs) (Award 1 mark for each correct conversion or zero) | 3 | ||
| Performed binary addition of 10110101₂ and 01101011₂ showing carry bits (Award 5 marks for correct addition with carry or zero) | 5 | ||
| Recorded the correct binary sum result (Award 3 marks for correct binary sum or zero) | 3 | ||
| Converted the binary sum back to decimal correctly (Award 3 marks for correct decimal conversion or zero) | 3 | ||
| Sub-Total | 15 | ||
| TASK 2: Integer Binary Subtraction | |||
| Performed binary subtraction of 01101011₂ from 10110101₂ using two's complement method (Award 6 marks for correct two's complement subtraction or zero) | 6 | ||
| Showed all working steps, including complement and addition (Award 4 marks for clear stepwise working or zero) | 4 | ||
| Recorded the correct binary difference result (Award 3 marks for correct binary difference or zero) | 3 | ||
| Converted the binary difference back to decimal correctly (Award 2 marks for correct decimal conversion or zero) | 2 | ||
| Sub-Total | 15 | ||
| PRODUCT CHECKLIST | |||
| Correctness of final binary addition and subtraction results with all working steps clearly shown (Award up to 10 marks for accuracy, completeness, and neatness) | 10 | ||
| Sub-Total | 10 | ||
| GRAND TOTAL | 40 | ||
At the start of this chapter we promised you would be able to:
Tick each one you can genuinely do.
So, are you there yet?
You're competent when you can confidently do 50% or more of what this chapter promised.
Sign in to record how you're doing.