0% found this document useful (0 votes)
125 views

Number Systems: Foundations of Computer Science Cengage Learning

The document discusses different number systems including decimal, binary, octal, and hexadecimal. It explains that these systems use different sets of symbols to represent numbers and defines the base of each system. The key points covered are: - Decimal uses base 10 and the symbols 0-9 - Binary uses base 2 and the symbols 0-1 - Octal uses base 8 and the symbols 0-7 - Hexadecimal uses base 16 and the symbols 0-9 plus A-F The document also explains how to convert numbers between these different number systems using various techniques based on place value and weighting of symbols.

Uploaded by

Farhad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

Number Systems: Foundations of Computer Science Cengage Learning

The document discusses different number systems including decimal, binary, octal, and hexadecimal. It explains that these systems use different sets of symbols to represent numbers and defines the base of each system. The key points covered are: - Decimal uses base 10 and the symbols 0-9 - Binary uses base 2 and the symbols 0-1 - Octal uses base 8 and the symbols 0-7 - Hexadecimal uses base 16 and the symbols 0-9 plus A-F The document also explains how to convert numbers between these different number systems using various techniques based on place value and weighting of symbols.

Uploaded by

Farhad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 86

Number

Systems
ITEC 1011 Introduction to Information Technologies
2.1 Foundations of Computer Science Cengage Learning
Objectives
After studying this chapter, the student should be able to:

 Understand the concept of number systems.


 Distinguish between non-positional and positional number
systems.
 Describe the decimal, binary, hexadecimal and octal system.
Convert a number in binary, octal or hexadecimal to a
number in the decimal system.
 Convert a number in the decimal system to a number in
binary, octal and hexadecimal.
 Convert a number in binary to octal and vice versa.
 Convert a number in binary to hexadecimal and vice versa.
 Find the number of digits needed in each system to represent
ITEC 1011
a particular value.Introduction to Information Technologies
2.2
2-1 INTRODUCTION

A number system defines how a number can be


represented using distinct symbols. A number can be
represented differently in different systems. For example,
the two numbers (2A)16 and (52)8 both refer to the same
quantity, (42)10, but their representations are different.

Several number systems have been used in the past


and can be categorized into two groups: positional and
non-positional systems. Our main goal is to discuss the
positional number systems, but we also give examples of
non-positional systems.
ITEC 1011 Introduction to Information Technologies
2.3
The decimal system (base 10)
The word decimal is derived from the Latin root decem (ten).
In this system the base b = 10 and we use ten symbols

S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

The symbols in this system are often referred to as decimal


digits or just digits.

ITEC 1011 Introduction to Information Technologies


2.4
The binary system (base 2)
The word binary is derived from the Latin root bini (or two
by two). In this system the base b = 2 and we use only two
symbols,

S = {0, 1}

The symbols in this system are often referred to as binary


digits or bits (binary digit).

ITEC 1011 Introduction to Information Technologies


2.5
The hexadecimal system (base 16)
The word hexadecimal is derived from the Greek root hex
(six) and the Latin root decem (ten). In this system the base
b = 16 and we use sixteen symbols to represent a number.
The set of symbols is

S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}

Note that the symbols A, B, C, D, E, F are equivalent to 10,


11, 12, 13, 14, and 15 respectively. The symbols in this
system are often referred to as hexadecimal digits.
ITEC 1011 Introduction to Information Technologies
2.6
The octal system (base 8)
The word octal is derived from the Latin root octo (eight). In
this system the base b = 8 and we use eight symbols to
represent a number. The set of symbols is

S = {0, 1, 2, 3, 4, 5, 6, 7}

ITEC 1011 Introduction to Information Technologies


2.7
Summary of the four positional systems
Table 2.1 shows a summary of the four positional number
systems discussed in this chapter.

ITEC 1011 Introduction to Information Technologies


2.8
Conversion
We need to know how to convert a number in one system to
the equivalent number in another system. Since the decimal
system is more familiar than the other systems, we first show
how to covert from any base to decimal. Then we show how
to convert from decimal to any base. Finally, we show how
we can easily convert from binary to hexadecimal or octal
and vice versa.

ITEC 1011 Introduction to Information Technologies


2.9
Conversion Among Bases
• The possibilities:

Decimal Octal

Binary Hexadecimal

pp. 40-46
ITEC 1011 Introduction to Information Technologies
Quick Example

2510 = 110012 = 318 = 1916

Base

ITEC 1011 Introduction to Information Technologies


Decimal to Decimal (just for fun)

Decimal Octal

Binary Hexadecimal

Next slide…
ITEC 1011 Introduction to Information Technologies
Weight

12510 => 5 x 100 = 5


2 x 101 = 20
1 x 102 = 100
125

Base

ITEC 1011 Introduction to Information Technologies


Binary to Decimal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Binary to Decimal
• Technique
– Multiply each bit by 2n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results

ITEC 1011 Introduction to Information Technologies


Example
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310

ITEC 1011 Introduction to Information Technologies


Octal to Decimal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Octal to Decimal
• Technique
– Multiply each bit by 8n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results

ITEC 1011 Introduction to Information Technologies


Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810

ITEC 1011 Introduction to Information Technologies


Hexadecimal to Decimal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Hexadecimal to Decimal
• Technique
– Multiply each bit by 16n, where n is the
“weight” of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results

ITEC 1011 Introduction to Information Technologies


Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810

ITEC 1011 Introduction to Information Technologies


Decimal to Binary

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant
bit)
– Second remainder is bit 1
– Etc.

ITEC 1011 Introduction to Information Technologies


Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1

12510 = 11111012

ITEC 1011 Introduction to Information Technologies


Octal to Binary

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Octal to Binary
• Technique
– Convert each octal digit to a 3-bit equivalent
binary representation

ITEC 1011 Introduction to Information Technologies


Example
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012

ITEC 1011 Introduction to Information Technologies


Hexadecimal to Binary

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit
equivalent binary representation

ITEC 1011 Introduction to Information Technologies


Example
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112

ITEC 1011 Introduction to Information Technologies


Decimal to Octal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Decimal to Octal
• Technique
– Divide by 8
– Keep track of the remainder

ITEC 1011 Introduction to Information Technologies


Example
123410 = ?8

8 1234
8 154 2
8 19 2
8 2 3
0 2

123410 = 23228

ITEC 1011 Introduction to Information Technologies


Decimal to Hexadecimal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder

ITEC 1011 Introduction to Information Technologies


Example
123410 = ?16

16 1234
16 77 2
16 4 13 = D
0 4

123410 = 4D216

ITEC 1011 Introduction to Information Technologies


Binary to Octal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Binary to Octal
• Technique
– Group bits in threes, starting on right
– Convert to octal digits

ITEC 1011 Introduction to Information Technologies


Example
10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278

ITEC 1011 Introduction to Information Technologies


Binary to Hexadecimal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Binary to Hexadecimal
• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits

ITEC 1011 Introduction to Information Technologies


Example
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
ITEC 1011 Introduction to Information Technologies
Octal to Hexadecimal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Octal to Hexadecimal
• Technique
– Use binary as an intermediary

ITEC 1011 Introduction to Information Technologies


Example
10768 = ?16

1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16
ITEC 1011 Introduction to Information Technologies
Hexadecimal to Octal

Decimal Octal

Binary Hexadecimal

ITEC 1011 Introduction to Information Technologies


Hexadecimal to Octal
• Technique
– Use binary as an intermediary

ITEC 1011 Introduction to Information Technologies


Example
1F0C16 = ?8

1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148
ITEC 1011 Introduction to Information Technologies
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF

Don’t use a calculator!

Skip answer Answer


ITEC 1011 Introduction to Information Technologies
Exercise – Convert …
Answer

Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF

ITEC 1011 Introduction to Information Technologies


Common Powers (1 of 2)
• Base 10
Power Preface Symbol Value
10-12 pico p .000000000001

10-9 nano n .000000001

10-6 micro  .000001

10-3 milli m .001

103 kilo k 1000

106 mega M 1000000

109 giga G 1000000000


1012 tera T 1000000000000

ITEC 1011 Introduction to Information Technologies


Common Powers (2 of 2)
• Base 2
Power Preface Symbol Value
210 kilo k 1024

220 mega M 1048576

230 Giga G 1073741824

• What is the value of “k”, “M”, and “G”?


• In computing, particularly w.r.t. memory,
the base-2 interpretation generally applies

ITEC 1011 Introduction to Information Technologies


Example
In the lab…
1. Double click on My Computer
2. Right click on C:
3. Click on Properties

/ 230 =

ITEC 1011 Introduction to Information Technologies


Exercise – Free Space
• Determine the “free space” on all drives on
a machine in the lab
Free space
Drive Bytes GB
A:
C:
D:
E:
etc.

ITEC 1011 Introduction to Information Technologies


Review – multiplying powers
• For common bases, add powers

ab  ac = ab+c

26  210 = 216 = 65,536


or…
26  210 = 64  210 = 64k

ITEC 1011 Introduction to Information Technologies


Binary Addition (1 of 2)
• Two 1-bit values

A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”

pp. 36-38
ITEC 1011 Introduction to Information Technologies
Binary Arithmetics

010111
Example: 011110 +
i. 0101112 + 0111102 = 110101
110101
2
ii. 1000112 + 0111002 = 1111112

ITEC 1011 Introduction to Information Technologies


Binary Addition (2 of 2)
• Two n-bit values
– Add individual bits
– Propagate carries
– E.g.,

1 1
10101 21
+ 11001 + 25
101110 46

ITEC 1011 Introduction to Information Technologies


Multiplication (1 of 3)
• Decimal (just for fun)

35
x 105
175
000
35
3675

pp. 39
ITEC 1011 Introduction to Information Technologies
Multiplication (2 of 3)
• Binary, two 1-bit values

A B AB
0 0 0
0 1 0
1 0 0
1 1 1

ITEC 1011 Introduction to Information Technologies


Multiplication (3 of 3)
• Binary, two n-bit values
– As with decimal values
– E.g.,
1110
x 1011
1110
1110
0000
1110
10011010
ITEC 1011 Introduction to Information Technologies
Subtraction ( – )

A B A-B
0 0 0
0 1 1 (borrow 1)
1 0 1
1 1 0

ITEC 1011 Introduction to Information Technologies


4. Division ( / )
0 / 1 = 0
1 / 1 = 1

ITEC 1011 Introduction to Information Technologies


Example:
i. 0101112 - 0011102 = 0010012

ii. 1000112 - 0111002 = 0001112

Exercise:
i. 1000100 – 010010 v. 110111 + 001101
ii. 1010100 + 1100 vi. 111000 + 1100110
iii. 110100 – 1001 vii. 110100 x 10
iv. 11001 x 11 viii. 11001 - 1110

ITEC 1011 Introduction to Information Technologies


Fractions
• Decimal to decimal (just for fun)

3.14 => 4 x 10-2 = 0.04


1 x 10-1 = 0.1
3 x 100 = 3
3.14

pp. 46-50
ITEC 1011 Introduction to Information Technologies
Fractions
• Binary to decimal

10.1011 => 1 x 2-4 = 0.0625


1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875

pp. 46-50
ITEC 1011 Introduction to Information Technologies
Fractions
• Decimal to binary .14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.

p. 50
ITEC 1011 Introduction to Information Technologies
Exercise – Convert ...

Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Don’t use a calculator!

Skip answer Answer


ITEC 1011 Introduction to Information Technologies
Exercise – Convert …
Answer

Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82

ITEC 1011 Introduction to Information Technologies


REPRESENTATION
OF
CHARACTER
• The BCD Code
• The Excess-3 Code
• The ASCII Code
• Encoders

ITEC 1011 Introduction to Information Technologies


The 8421 BCD Code
• BCD stands for Binary-Coded Decimal.

• A BCD number is a four-bit binary group that


represents one of the ten decimal digits 0 through 9.

Example:
Decimal number 4926 4 9 2 6

8421 BCD coded number 0100 1001 0010 0110


ITEC 1011 Introduction to Information Technologies
QUIZ
Convert the BCD coded number
1000 0111 0001 into decimal.

BCD Coded Number 1000 0111 0001

Decimal Number 8 7 1

ITEC 1011 Introduction to Information Technologies


QUIZ

Convert the decimal number


350 to its BCD equivalent.

Decimal Number 3 5 0

BCD Coded Number 0011 0101 0000

ITEC 1011 Introduction to Information Technologies


The Excess-3 Code
• Add 3 to each digit of decimal and
convert to 4-bit binary form
• A BCD code (not 8421 BCD)
Decimal Binary +3 Excess-3 Sample Problem:
0 0000 0011 0011
1 0001 0011 0100
2 0010 0011 0101 Decimal 3 5 9
3 0011 0011 0110
4 0100 0011 0111
5 0101 0011 1000
6 0110 0011 1001 Excess-3 0110 1000 1100
7 0111 0011 1010
8 1000 0011 1011
9 1001 0011 1100
ITEC 1011 Introduction to Information Technologies
QUIZ

1. To form an excess-3 coded number,


decimal 3 is added to the decimal
number and this is converted to its
4-bit binary code. (True or False) True

2. The excess-3 BCD number 1010 0100


equals __________ in decimal. 71

3. The decimal number 428 equals


what excess-3 number. 0111 0101 1011
ITEC 1011 Introduction to Information Technologies
The ASCII Code
• ASCII is an acronym for American
Standard Code for Information Interchange
• Represents numbers, letters, punctuation
marks and control characters
• Standard ASCII is a 7-bit code (127
characters)
• Extended ASCII (IBM ASCII), an 8-bit
code, is also very popular
• Extended ASCII adds graphics and math
symbols toIntroduction
ITEC 1011 code (total of 256
to Information symbols)
Technologies
QUIZ
1. A common 7-bit code used to represent
numbers, letters, punctuation marks,
and control characters is known by
the acronym __________. ASCII

2. The acronym ASCII stands for American Standard


__________________________. Code for Information
Interchange
3. Extended ASCII code is a(n)
__________ (8-bit, 10-bit) code 8-bit
which adds graphic and math
symbols to ASCII for a total of
256 symbols.Introduction to Information Technologies
ITEC 1011
Electronic Encoder - Decimal to BCD
BCD output
Decimal input
00
1101
0
7
Decimal
5 to
BCD
3 Encoder
0

• Encoders are available in IC form.


• This encoder translates from decimal
ITEC 1011 input toIntroduction
BCD output.to Information Technologies
Even/odd parity (1)
• Computers can sometimes make errors when they
transmit data.
• Even/odd parity:
– is basic method for detecting if an odd number of bits
has been switched by accident.
• Odd parity:
– The number of 1-bit must add up to an odd number
• Even parity:
– The number of 1-bit must add up to an even number

ITEC 1011 Introduction to Information Technologies


Even/odd parity (2)
• The computer knows which parity it is using
• If it uses an even parity:
– If the number of of 1-bit add up to an odd number then
it knows there was an error:
• If it uses an odd:
– If the number of of 1-bit add up to an even number then
it knows there was an error:
• However, If an even number of 1-bit is flipped the parity
will still be the same. But an error occurs
– The even/parity can’t this detect this error:

ITEC 1011 Introduction to Information Technologies


Example (1)
• Suppose you receive a binary bit word
“0101” and you know you are using an odd
parity.
• Is the binary word errored?
• The answer is yes:
• There are 2 1-bit, which is an even number
• We are using an odd parity
• So there must have an error.

ITEC 1011 Introduction to Information Technologies


Parity Bit

• A single bit is appended to each data chunk


– makes the number of 1 bits even/odd
• Example: even parity
– 1000000(1)
– 1111101(0)
– 1001001(1)
• Example: odd parity
– 1000000(0)
– 1111101(1)
– 1001001(0)
ITEC 1011 Introduction to Information Technologies
Exercise 1
• Suppose you are using an odd parity. What
should the binary word “1010” look like
after you add the parity bit?
• Answer:
– There is an even number of 1-bits.
– So we need to add another 1-bit
– Our new word will look like “10101”.

ITEC 1011 Introduction to Information Technologies


Exercise 2
• Suppose you are using an even parity. What
should the binary word “1010” look like
after you add a parity bit?
• Answer:
– There is an even number of 1’s.
– So we need to add another 0
– Our new word will look like “10100”.

ITEC 1011 Introduction to Information Technologies


Thank you

Next topic

ITEC 1011 Introduction to Information Technologies

You might also like