Computer Science  ·  Level 6
Computer Organisation And Architecture
Chapter 5: Computer arithmetic and logic
📚 6 Topics
⚑ What you will be able to do

By the end of this chapter, you will be able to:

  • Identify and use different number systems correctly in computer calculations.
  • Apply integer and floating-point number representations based on IEEE standards confidently.
  • Perform accurate integer and floating-point arithmetic operations.
  • Use logic operators correctly when working with computer arithmetic and logic problems.
  • Carry out logic operations accurately by following the proper methods.
  • Represent logic operations clearly and correctly using standard methods.

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.

5.1 Number systems

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.

5.1.1 Types of number 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.

Binary number system

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.

  • Each digit is called a bit.
  • The rightmost bit represents \(2^0\), the next \(2^1\), and so on.
  • Binary is used in machine-level programming and hardware design.
  • It represents logical values in computer logic gates.
  • Binary arithmetic underlies all higher-level computations.

Octal number system

The octal system uses base 8 and digits 0 to 7.

  • Each octal digit represents three binary bits.
  • It provides a shorthand for binary numbers, simplifying reading and writing.
  • Frequently used in older computing systems and permissions in Unix/Linux.
  • It reduces the length of binary sequences.
  • Useful in error detection and data compression techniques.

Decimal number system

The decimal system uses base 10 and digits 0 to 9.

  • It is the standard human counting system.
  • Computers convert decimal inputs into binary for processing.
  • Most programming languages accept decimal literals.
  • Decimal system is used in financial and business applications.
  • Programming often requires conversion between decimal and other bases.

Hexadecimal number system

The hexadecimal system uses base 16 and digits 0 to 9 plus A to F.

  • Each hex digit represents four binary bits.
  • It is widely used in memory addressing and debugging.
  • Hexadecimal simplifies large binary number representation.
  • Common in color codes in web design and graphics programming.
  • Used extensively in low-level programming and assembly language.

Worked Examples

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

5.1.2 Operations in number systems

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

Binary addition follows rules similar to decimal addition but with base 2.

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 10 (carry 1 to next higher bit)

Binary subtraction

Binary subtraction uses borrow similar to decimal subtraction.

  • 0 - 0 = 0
  • 1 - 0 = 1
  • 1 - 1 = 0
  • 0 - 1 requires borrowing 1 from next higher bit
Worked Example

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:

  • Bit 0: \(1 - 0 = 1\)
  • Bit 1: \(0 - 1\) (need to borrow)
    • Borrow 1 from bit 2: bit 2 becomes 0, bit 1 becomes \(2 - 1 = 1\)
  • Bit 2: \(0 - 0 = 0\) (after borrowing)
  • Bit 3: \(1 - 1 = 0\)

Final result: \(0011_2\)

Answer: \(11_2\) (decimal 3)

Binary multiplication

Binary multiplication is like decimal multiplication but simpler.

  • Multiply each bit of the multiplier by the multiplicand.
  • Shift results according to bit position.
  • Add all shifted results.
Worked Example

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:

  • \(101 \times 1 = 101\) (no shift)
  • \(101 \times 1 = 101\) (shift left by 1: 1010)

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

Binary division involves repeated subtraction of divisor shifted appropriately.

  • Compare divisor with leftmost bits of dividend.
  • Subtract if divisor less or equal, else bring down next bit.
  • Continue until all bits processed.
Worked Example

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:

  • 2 fits into 13 six times, remainder 1.
  • In binary:
    • 10 fits into 11 (first two bits of 1101), quotient bit 1, subtract 10 from 11: 11 - 10 = 1
    • Bring down next bit: 1 becomes 10 (after shifting), 10 fits into 10 once, quotient bit 1, subtract 10 from 10: 10 - 10 = 0
    • Bring down last bit: 0 becomes 1, 10 does not fit, quotient bit 0, remainder 1

Quotient: \(110_2\) (decimal 6), Remainder: \(1_2\)

Answer: Quotient = \(110_2\), Remainder = \(1_2\)

Worked Examples

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

5.1.3 Conversion between number systems

Converting numbers accurately between decimal, binary, octal, and hexadecimal is vital for programming, debugging, and data representation in Kenyan IT environments.

Decimal to binary conversion

Use successive division by 2, recording remainders.

Binary to decimal conversion

Multiply each bit by \(2^{position}\) and sum all.

Binary to octal and hexadecimal conversion

Group binary digits into sets of 3 (octal) or 4 (hexadecimal) starting from right, then convert each group to respective digit.

Octal and hexadecimal to binary conversion

Convert each octal or hex digit to its binary equivalent.

Worked Examples

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

Practice Questions

  1. Convert decimal 29 to binary and octal. (5 marks)
  2. Perform binary addition of 10110 and 11001. (5 marks)
  3. Convert hexadecimal 3B to decimal and binary. (5 marks)
  4. Subtract binary 1001 from 1110. (5 marks)
  5. Convert binary 1110001 to octal and hexadecimal. (5 marks)
The rest of this chapter
🔒

Create a free account to open more of this chapter.

Free: practical guides, quick cards, workplace scenarios and more.

Create a free account
🔒5.2 IEEE-based Integer and Floating Point Representations

In computer science, especially within Kenyan software development and data science sectors, understanding IEEE standards for integer and floating-point representations is critical. These standards ensure consistency in how numbers are stored and processed acr…

🔒5.3 Integer and Floating-Point Arithmetic

Arithmetic operations on integers and floating-point numbers are fundamental in computer science, particularly in algorithm implementation and system programming. Kenyan software engineers must understand these operations to optimize performance and ensure acc…

🔒5.4 Logic operators

Logic operators form the foundation of computer arithmetic and decision-making processes. In Kenyan software development firms and computer science research institutions, understanding these operators is crucial for designing algorithms, optimizing code, and i…

🔒5.5 Logic operations

Logic operations are fundamental to computer arithmetic and form the basis of all computations and decision-making processes in computer systems. In Kenyan software development, cybersecurity, and data processing environments, understanding these operations en…

🔒5.6 Representing logic operations

Logic operations form the foundation of computer arithmetic and decision-making processes. In Kenyan software development projects, especially those involving embedded systems or digital circuit design for financial institutions or county government data cente…

Chapter Summary

This 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.

Self-Assessment

🔒 PDFDownload this self-assessment, with answers

Written Assessment

  1. Convert the decimal number \(45\) to its binary equivalent. (2 marks)

  2. Add the binary numbers \(1011_2\) and \(1101_2\). Provide the result in binary. (3 marks)

🔒18 more in this section.

Chapter Examination Questions

🔒 PDFDownload these examination questions, with worked answers

SECTION A (40 Marks) - Answer ALL Questions

  1. Convert the decimal number 156 to its binary, octal, and hexadecimal equivalents. (4 marks)
  2. Perform the binary addition of \(101101_2\) and \(11011_2\). Show your working. (4 marks)
🔒18 more in this section.

Chapter Practical Activities

Practical 1: Convert numbers between binary, decimal, octal, and hexadecimal systems

Computer Science · Level 6
Computer Organisation And Architecture
PRACTICAL ASSESSMENT
TIME: 4 HOURS
⬇ PDFCandidate Instructions (Candidate Tool)

Type: Individual

INSTRUCTIONS TO CANDIDATE:
1.  You are required to perform the following task:
i.  Convert the following numbers: decimal 3457, binary 1101101, octal 725, and hexadecimal 1F4A into their equivalent binary, decimal, octal, and hexadecimal forms respectively, presenting the results in a formatted table.
2.  You have been provided with the following resources for the practical task:
Tools & EquipmentMaterials
A working computerPlain paper
Scientific calculator
Pen
⬇ PDFResources Required (Cutting List)
S/NItemQuantity
1A working computer1 Pc per Candidate
2Scientific calculator1 Pc per Candidate
3Plain paper5 Sheets per Candidate
4Pen1 Pc per Candidate
⬇ PDFAssessor Guide
Items to be EvaluatedMarks AvailableMarks ObtainedComments
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-Total40
PRODUCT CHECKLIST
All converted numbers are accurate and match expected values
(Award 10 marks for 100% accuracy; partial credit for minor errors)
10
Sub-Total10
GRAND TOTAL50
ASSESSMENT OUTCOME:   ☐ Competent    ☐ Not Yet Competent (competent if at least 50%)

Practical 2: Perform Integer Addition and Subtraction Using Binary Arithmetic

Computer Science · Level 6
Computer Organisation And Architecture
PRACTICAL ASSESSMENT
TIME: 4 HOURS
⬇ PDFCandidate Instructions (Candidate Tool)

Type: Individual

INSTRUCTIONS TO CANDIDATE:
1.  You are required to perform the following task:
i.  Perform and record the binary addition and subtraction of two 8-bit integers: 10110101₂ and 01101011₂, showing all working steps.
2.  You have been provided with the following resources for the practical task:
Tools & EquipmentMaterials
Scientific calculator with binary modePlain paper
Computer with binary arithmetic softwarePen or pencil
⬇ PDFResources Required (Cutting List)
S/NItemQuantity
1Scientific calculator with binary mode1 Pc per Candidate
2Computer with binary arithmetic software (e.g., a binary calculator or programming IDE)1 Pc per Candidate
3Plain paper5 Sheets per Candidate
4Pen or pencil1 Pc per Candidate
⬇ PDFAssessor Guide
Items to be EvaluatedMarks AvailableMarks ObtainedComments
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-Total15
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-Total15
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-Total10
GRAND TOTAL40
ASSESSMENT OUTCOME:   ☐ Competent    ☐ Not Yet Competent (competent if at least 50%)
🔒

Free: practical guides, quick cards, workplace scenarios and more.

Create a free account
🔒Perform Binary Integer Multiplication of Two 8-bit NumbersPractical 3
🔒Perform IEEE 754 Floating-Point Addition and SubtractionPractical 4
🔒Perform IEEE 754 Floating-Point Multiplication and DivisionPractical 5
🔒Representation of Numbers Using IEEE Standard FormatsPractical 6
🔒Apply Basic Logic Operators to Binary InputsPractical 7
🔒Construct truth tables for specified logic expressionsPractical 8
🔒Simplify Boolean Expressions Using Karnaugh MapsPractical 9
🔒Identify and Demonstrate Operation of Logic GatesPractical 10
🔒Perform manual binary division of two 8-bit numbersPractical 11
🔒Evaluate complex logic expressions combining AND, OR, NOT, NAND, and NOR operatorsPractical 12
🔒Convert IEEE 754 Floating-Point Numbers to Signed 32-bit Integer FormatPractical 13
🔒Perform Binary Subtraction Using Two's Complement MethodPractical 14
🔒Design and Test a 2-Input Logic Gate Circuit for a Given Boolean FunctionPractical 15
Flashcards 20 cards Study deck ▾
Question
1

↻ Tap card to reveal answer
🔒

18 more in this section.

Create a free account
Test Yourself 16 questions Start quiz ▾
0%
0 / 2
🔒

14 more in this section.

Create a free account
Am I competent?

At the start of this chapter we promised you would be able to:

  • Identify and use different number systems correctly in computer calculations.
  • Apply integer and floating-point number representations based on IEEE standards confidently.
  • Perform accurate integer and floating-point arithmetic operations.
  • Use logic operators correctly when working with computer arithmetic and logic problems.
  • Carry out logic operations accurately by following the proper methods.
  • Represent logic operations clearly and correctly using standard methods.

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.