Chapter 1 - Bases and Number Representation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 33

Chapter 1:

Bases and Number


Representation
 Introduction
 Conversion of base number
 Arithmetic in non-decimal bases
Course learning outcomes (CLOs)
At the end of this course, students should be able to
1. solve mathematics problems in computing using discrete mathematics;
2. use algebra, set and the graph theory to solve mathematical problems in computing;
3. analyse the logic and graph theory using the algebraic method.

N. Othman 2
Lesson learning outcomes (LLOs)
At the end of this lesson, student should be able to
1. explain the bases and number representations,
2. convert the number from one base to another base, and
3. perform the arithmetic operation in non-decimal bases.

N. Othman 3
Introduction: real number system
Numbers can be represented in various ways. For example, the number ‘four’ can be written in the usual
notation as 4, in Roman numerals as IV.
Real numbers
Type of real numbers (nearly any number you can think of):
• The natural numbers (also called the positive integers), exclude zero, e.g. 1, 2, 3, 4, …
• The whole numbers, include zero but exclude negative numbers, fractions and decimals, e.g. 0, 1, 2, …
• The integers, include all whole numbers and all negative of whole numbers, e.g. -3, -2, -1, 0, 1, 2, 3, …
• The rational numbers, can be expressed in fraction form, e.g. and . Any rational number can also be written
as a terminating or recurring decimal, e.g. and .

Note: Imaginary numbers and infinity are NOT real numbers.

N. Othman 4
Introduction: real number system
Venn diagram of real number system

Real

Source: https://www.onlinemathlearning.com/
N. Othman 5
Introduction: bases and number representation
Real number representations

The decimal number The binary number The octal number The hexadecimal number

• Base: 10 • Base: 2 • Base: 8 • Base: 16


• Symbols: • Symbols: • Symbols: • Symbols:
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} {0, 1} {0, 1, 2, 3, 4, 5, 6, 7} {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
• Examples: • Examples: • Examples: A, B, C, D, E, F}
• Examples:

N. Othman 6
Conversion of base number
Map of conversion

OCTAL

Note:
There is no direct way for
conversion between octal
DECIMAL BINARY
and hexadecimal. The
conversion need to use
binary as an intermediary.

HEXADECIMAL

N. Othman 7
Conversion of base number: Decimal and Binary
• Odd numbers have a binary representation ending in 1
• Even numbers have a binary representation ending in 0

Conversion 1: Decimal to Binary


Example:
Convert into binary number.
Solution:
Step 1: Separate into two parts; whole number and decimal.

whole number decimal

N. Othman 8
Conversion of base number: Decimal and Binary
Conversion 1: Decimal to Binary
Solution (cont.): Step 3: Convert the decimal part to binary using
multiplication method.
156.8125=156+ 0.8125
whole number decimal

Step 2: Convert the whole number part to binary using


division method.

Step 4: Combine the binary of whole number and


decimal.

N. Othman 9
Conversion of base number: Decimal and Binary
Conversion 1: Decimal to Binary
Try it yourself:
Convert the following into binary number. Keep 8 bits to the right of the binary point when the
conversion is not exact.

N. Othman 11
Conversion of base number: Decimal and Binary
Conversion 2: Binary to Decimal
Example:
Convert into decimal number.
Solution:
Step 1: Write the ‘weight’ of each bit. The weight Step 2: Multiply each bit by and add the results.
(denotes by ) is the position of the bit, starting from on
the right of whole number.

N. Othman 13
Conversion of base number: Decimal and Binary
Conversion 2: Binary to Decimal
Try it yourself:
Convert the following into decimal number.

N. Othman 15
Conversion of base number: Decimal and Octal
Conversion 1: Decimal to Octal
Example:
Convert into octal number.
Solution:
Step 1: Separate into two parts; whole number and decimal.

whole number decimal

N. Othman 16
Conversion of base number: Decimal and Octal
Conversion 1: Decimal to Octal
Solution (cont.): Step 3: Convert the decimal part to octal using
multiplication method.
156.8125=156+ 0.8125
whole number decimal

Step 2: Convert the whole number part to octal using


division method.

Step 4: Combine the octal of whole number and


decimal.

N. Othman 18
Conversion of base number: Decimal and Octal
Conversion 1: Decimal to Octal
Try it yourself:
Convert the following into octal number. Keep 8 bits to the right of the octal point when the
conversion is not exact.

N. Othman 20
Conversion of base number: Decimal and Octal
Conversion 2: Octal to Decimal
Example:
Convert into decimal number.
Solution:
Step 1: Write the ‘weight’ of each bit. The weight Step 2: Multiply each bit by and add the results.
(denotes by ) is the position of the bit, starting from on
the right of whole number.

N. Othman 22
Conversion of base number: Decimal and Octal
Conversion 2: Octal to Decimal
Try it yourself:
Convert the following into decimal number.

N. Othman 23
Conversion of base number: Decimal and Hex-
Conversion 1: Decimal to Hex-
Example:
Convert into hexadecimal number.
Solution:
Step 1: Separate into two parts; whole number and decimal.

whole number decimal

N. Othman 24
Conversion of base number: Decimal and Hex-
Conversion 1: Decimal to Hex-
Solution (cont.): Step 3: Convert the decimal part to hex- using
multiplication method.
156.8125=156+ 0.8125
whole number decimal

Step 2: Convert the whole number part to hex- using


division method.

Step 4: Combine the hex- of whole number and


decimal.

N. Othman 25
Conversion of base number: Decimal and Hex-
Conversion 1: Decimal to Hex-
Try it yourself:
Convert the following into hexadecimal number. Keep 8 bits to the right of the hexadecimal point
when the conversion is not exact.

N. Othman 26
Conversion of base number: Decimal and Hex-
Conversion 2: Hex- to Decimal
Example:
Convert into decimal number.
Solution:
Step 1: Write the ‘weight’ of each bit. The weight Step 2: Multiply each bit by and add the results.
(denotes by ) is the position of the bit, starting from on
the right of whole number.

N. Othman 27
Conversion of base number: Decimal and Hex-
Conversion 2: Hex- to Decimal
Try it yourself:
Convert the following into decimal number.

N. Othman 28
Conversion of base number: Binary and Octal
Table of conversion between Binary and Octal Conversion 1: Binary to Octal
Octal Binary Example:
0 000 Convert into octal number.
1 001
2 010 Solution:
3 011
4 100
5 101
6 110
7 111 Conversion 2: Octal to Binary
Example:
Convert into binary number.
Solution:

N. Othman 30
Conversion of base number: Binary and Octal
Try it yourself:
1. Convert the following into octal number.

2. Convert the following into binary number.

N. Othman 31
Conversion of base number: Binary and Hex-
Table of conversion between Binary and Hex- Conversion 1: Binary to Hex-
Hexadecimal Binary Example:
0 0000 Convert into hexadecimal number.
1 0001
2 0010 Solution:
3 0011
4 0100
5 0101
6 0110
7 0111 Conversion 2: Hex- to Binary
8 1000
Example:
9 1001
A 1010 Convert into binary number.
B 1011
C 1100 Solution:
D 1101
E 1110
F 1111

N. Othman 33
Conversion of base number: Binary and Hex-
Try it yourself:
1. Convert the following into hexadecimal number.

2. Convert the following into binary number.

N. Othman 34
Conversion of base number: Octal and Hex-
• No direct way.
• We have to use binary as an intermediary.
Conversion 2: Hex- to Octal
Conversion 1: Octal to Hex- Example:
Example: Convert into octal number.
Convert into hexadecimal number. Solution:
Solution:

N. Othman 35
Conversion of base number: Octal and Hex-
Try it yourself:
1. Convert the following into hexadecimal number.

2. Convert the following into octal number.

N. Othman 36
Arithmetic in non-decimal bases
Table of binary addition Example:
Solve the following. Give your answer in binary
0 0 number.

0 1
1 0
1 1 Solution:

Table of binary multiplication

0 0
0 1
1 0
1 1
N. Othman 37
Arithmetic in non-decimal bases
Try it yourself:
Solve the following, and give your answer in binary number.

For additions in hexadecimal and octals, convert them to binary first. Then convert back the final
answer to the required form.

N. Othman 38
2’s Complement
The 2’s complement method:
Step 1: Write the absolute value of the given number in binary form. Prefix this number with 0 indicate that it is positive. Take
note of number of bits. You may need to add more zeros to fill up the bit space.
Step 2: Take the complement of each bit by changing zeroes to ones and ones to zero.
Step 3: Add 1 to your result.
Step 4: First digit represents the sign (0: positive, 1 negative). Convert the rest back to decimal.

Example:
Convert 4510 to the 2’s complement.
Answer: (8-bit: add 2 zeros to the front)

N. Othman 39
Binary Coded Decimal (BCD)
BCD:
In binary coded decimal (BCD) coding scheme, each decimal digit is represented as a
group of 4-bit binary number. For a multi-digit decimal number, each digit of the decimal
number is encoded separately in the BCD.

Example: Convert (125)10 into its equivalent binary coded decimal (BCD) code.

Answer:

N. Othman 40
Summary
Do it yourself:
Please summarize this chapter (brief notes, formulas, etc.).

N. Othman 41

You might also like