@Lecture-COAL: Course Instructor: Khawaja Ubaid Ur Rehman Section: V3/V4/V5 SST
@Lecture-COAL: Course Instructor: Khawaja Ubaid Ur Rehman Section: V3/V4/V5 SST
@Lecture-COAL: Course Instructor: Khawaja Ubaid Ur Rehman Section: V3/V4/V5 SST
Numbers System
1
Learning Goals for Today
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
1’s multiplier
Decimal (base 10) numbers are expressed in the
positional notation
10
10’s multiplier
Decimal (base 10) numbers are expressed in the
positional notation
100
100’s multiplier
Decimal (base 10) numbers are expressed in the
positional notation
1000
1000’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation
1’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation
2’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation
4’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation
8’s multiplier
Binary (base 2) numbers are also expressed in the
positional notation
16
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.
1001011
Check
1100100
Common Number Systems
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-
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
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
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
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 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
2 3 E
10768 = 23E16
Quick Example Dec 2 Hex
Decimal Octal
Binary Hexadecimal
Hexadecimal to Octal
• Technique
– Use binary as an intermediary
Example
1F0C16 = ?8
1 F 0 C
1 7 4 1 4
1F0C16 = 174148
Exercise – Convert
Hexa-
Decimal Binary Octal decimal
33
1110101
Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
Class Activity #1 – Convert …
Hexa-
Decimal Binary Octal decimal
703
1AF
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
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 𝐶 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