You are on page 1of 81

@Lecture-COAL

Numbers System

Course Instructor: Khawaja Ubaid ur Rehman


Section: V3/V4/V5
SST

1
Learning Goals for Today

1. To become familiar with number system used by the


microprocessors - binary numbers

2. To become able to perform decimal-to-other base


conversions
BINARY
(BASE 2)
numbers
DECIMAL
(BASE 10)
numbers
Decimal (base 10) number system consists of 10
symbols or digits

0 1 2 3 4
5 6 7 8 9
Binary (base 2) number system consists of just
two

01
Other popular number systems

• Octal
– base = 8
– 8 symbols (0,1,2,3,4,5,6,7)

• Hexadecimal
– base = 16
– 16 symbols (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
Decimal (base 10) numbers are expressed in the
positional notation

The right-most is the least significant digit

4202 = 2x100 + 0x101 + 2x102 + 4x103

The left-most is the most significant digit


Decimal (base 10) numbers are expressed in the
positional notation

4202 = 2x100 + 0x101 + 2x102 + 4x103

1’s multiplier
Decimal (base 10) numbers are expressed in the
positional notation

10

4202 = 2x100 + 0x101 + 2x102 + 4x103

10’s multiplier
Decimal (base 10) numbers are expressed in the
positional notation

100

4202 = 2x100 + 0x101 + 2x102 + 4x103

100’s multiplier
Decimal (base 10) numbers are expressed in the
positional notation

1000

4202 = 2x100 + 0x101 + 2x102 + 4x103

1000’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation

The right-most is the least significant digit

10011 = 1x20 + 1x21 + 0x22 + 0x23 + 1x24

The left-most is the most significant digit


Binary (base 2) numbers are also expressed in the
positional notation

10011 = 1x20 + 1x21 + 0x22 + 0x23 + 1x24

1’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation

10011 = 1x20 + 1x21 + 0x22 + 0x23 + 1x24

2’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation

10011 = 1x20 + 1x21 + 0x22 + 0x23 + 1x24

4’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation

10011 = 1x20 + 1x21 + 0x22 + 0x23 + 1x24

8’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation

16

10011 = 1x20 + 1x21 + 0x22 + 0x23 + 1x24

16’s multiplier
Counting in Counting in
Decimal Binary
0 10 20 30 0 1010 10100 11110
1 11 21 31 1 1011 10101 11111
2 12 22 32 10 1100 10110 100000
3 13 23 33 11 1101 10111 100001
4 14 24 34 100 1110 11000 100010
5
15 25 35 101 1111 11001 100011
6
7
16 26 36 110 10000 11010 100100
8 17 27 . 111 10001 11011 .
9 18 28 . 1000 10010 11100 .
19 29 . 1001 10011 11101 .
Why binary
Because this system is natural for digital computers
?
The fundamental building block of a digital computer – the
switch – possesses two natural states, ON & OFF.

It is natural to represent those states in a number system


that has only two symbols, 1 and 0, i.e. the binary number
system

In some ways, the decimal number system is natural to us


humans. Why?
bit
binary digit
Byte = 8 bits
Decimal Binary
conversion
Convert 75 to Binary
2 75 remainder
2 37 1
2 18 1
2 9 0
2 4 1
2 2 0
2 1 0

1001011
Check

1001011 = 1x20 + 1x21 + 0x22 + 1x23 +


0x24 + 0x25 + 1x26
= 1 + 2 + 0 + 8 + 0 + 0 + 64
= 75
Convert 100 to Binary
2 100 remainder
2 50 0
2 25 0
2 12 1
2 6 0
2 3 0
2 1 1
1

1100100
Common Number Systems

Used by Used in computers?


System Base Symbols humans?

Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Yes No

Binary 2 0, 1 No Yes
Octal 8 0, 1, 2, 3, 4, 5, 6, 7 No No

Hexa- 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, No Special Cases


decimal A, B, C, D, E, F
Quantities/Counting (1 of 3)

Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
p. 33
Quantities/Counting (2 of 3)

Hexa-
Decimal Binary Octal decimal
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Quantities/Counting (3 of 3)

Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17 Etc.
Conversion Among Bases

• The possibilities:

Decimal Octal

Binary Hexadecimal

pp. 40-46
Decimal to Decimal (just for fun)

Decimal Octal

Binary Hexadecimal

Next slide…
Weight

12510 => 5 x 100 = 5


2 x 101 = 20
1 x 102 = 100
125

Base
Binary to Decimal

Decimal Octal

Binary Hexadecimal
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
Example of Binary to Decimal

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
Octal to Decimal

Decimal Octal

Binary Hexadecimal
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
Example of Octal to Decimal

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

Decimal Octal

Binary Hexadecimal
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
Example of Hexadecimal to Decimal
ABC16 C
=> x 160 = 12 x1 = 12
B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Decimal to Binary

Decimal Octal

Binary Hexadecimal
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.
Example of Decimal to Binary

12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
12510 = 11111012
0 1
Octal to Binary

Decimal Octal

Binary Hexadecimal
Octal to Binary

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

7058 = ?2

7 0 5

111 000 101

7058 = 1110001012
Hexadecimal to Binary

Decimal Octal

Binary Hexadecimal
Hexadecimal to Binary

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

10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112
Decimal to Octal

Decimal Octal

Binary Hexadecimal
Decimal to Octal

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

123410 = ?8

8 1234
8 154 2
8 19 2
8 2 3
0 2
123410 = 23228
Decimal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Decimal to Hexadecimal

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

123410 = ?16

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

123410 = 4D216
Binary to Octal

Decimal Octal

Binary Hexadecimal
Binary to Octal

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

10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278
Binary to Hexadecimal

Decimal Octal

Binary Hexadecimal
Binary to Hexadecimal

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

10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
Octal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Octal to Hexadecimal

• Technique
– Use binary as an intermediary
Example

10768 = ?16

1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16
Quick Example Dec 2 Hex

2510 = 000110012 = 318 = 1916


Base
Hexadecimal to Octal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Octal

• Technique
– Use binary as an intermediary
Example

1F0C16 = ?8

1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148
Exercise – Convert

Hexa-
Decimal Binary Octal decimal
33
1110101

Don’t use a calculator!

Skip answer Answer


Exercise – Convert …
Answer

Hexa-
Decimal Binary Octal decimal

33 100001 41 21
117 1110101 165 75
Class Activity #1 – Convert …
Hexa-
Decimal Binary Octal decimal

703
1AF

Don’t use a calculator!

Skip answer Answer

ITC concepts revision 73


Class Activity #1 – Convert …
Answer

451 111000011 703 1C3


431 110101111 657 1AF

Discovering Computers 2012: Chapter 6 74


 Convert into Binary
Number Remainder
2 56
2 28 0
2 14 0
2 7 0
2 3 1
2 1 1

 56=111000(2)
Result Fractional Integral
2 x 0.25 0.5 5 0
2 x 0.5 1.0 0 1

 
0.25
 So,
Converting Fractional Decimal Numbers to
Binary
• Example
  1: Convert into Binary. Give answer
up to 6 decimals.
Result Fractional part Integral part
2 x 0.56 1.12 12 1
2 x 0.12 0.24 24 0
2 x 0.24 0.48 48 0
2 x 0.48 0.96 96 0
2 x 0.96 1.92 92 1
2 x 0.92 1.84 84 1
2 x 0.84 1.68 68 1
2 x 0.68 1.36 36 1

 0.56(10 )=0.10 0 01111(2)


 Convert into decimal

1110.11
•     (2)
 Convert into hexadecimal

Number Remainder
16 185
16 11 9
16 0 11=B

 185(10) =0 𝐵 9( 16)
Result Fractional Part Integral Part
16 x 0.3 4.8 8 4
16 x 0.8 12.8 8 12=C
16 x 0.8 12.8 8 12=C

 0.3(10) =0.4 𝐶 (Note:


16) because C in the repeating value
therefore as a convention we shall take
 
So, it once only
 Convert into decimal

0  𝐶 9.3 𝐷(16)
•  
 Convert into hexadecimal

•First
  divide your number into groups of 4 bits starting from
the decimal point position so is divided into following
three groups 1100 and 0010 on the left side of decimal
point and 1000 on the right side of decimal point.
1100 =
0010 =
1000 =
can be written as
So,
 Convert into octal

•   1: First divide your number into groups of 3 bits starting from


Step
the right side. So, is divided into the following three groups
010,011 on the left of decimal and 110 on the right side of decimal
Step 2: Convert each group into octal

can be written as 011 010. 110 =

You might also like