0% found this document useful (0 votes)
17 views59 pages

Lecture 1

Uploaded by

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

Lecture 1

Uploaded by

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

Lecture 1

Data Representation ::
Data Representation

The term data representation means the code or


technique in which the data can be represented.
Number Systems

Number systems are very important to understand


because the design and organization of a computer
depends on the number systems. The four kind of
number system used by the digital computer –
1.Decimal number system
2.Binary number system
3.Octal number system
4.Hexadecimal number system
Data Representation

How do computers represent data?


Ø Most computers are digital
§ Recognize only two
discrete states: on or off
§ Use a binary system to
recognize two states
§ Use number system with
two unique digits: 0 and 1,
called bits (short for
binary digits)
§ Smallest unit of data
computer can process
Data Representation
The “WHY” side
Binary numbers
All computers work with 0’s and 1’s so it is like learning
alphabets before learning English

Base conversion
For convenience, people use other bases (like decimal,
hexadecimal) and we need to know how to convert from one to
another.

Number systems
There are more than one way to express a number in binary. So
1010 could be -2, -5 or -6 and need to know which one.
Number representation

Bases we will use


• Base 2 (i.e., binary): only use 0 and 1
• Base 8 (octal): only use 0,1,…7
• Base 10 (decimal): use 0, 1, …., 9
• Base 16 (hexadecimal): use 0,1,…9, A,B,C,D,E,F
Base
The base of a number system is the number of possible values
! for each digit.

Values for each Base Name of


digit number system
0 to 9 10? ?
Denary/Decimal
0 to 1 2? Binary ?
0 to 7 8? Octal ?
0 to F 16? Hexadecimal
?
(A=10, B=11, ... F=15)
Decimal/ denary Number System
Can you spot any patterns in how we’re counting up?
How does this pattern relate to the ‘base’?

• The decimal number system consists of 10 digits


namely 0 to 9.

• Since the decimal number system consists of 10


digits, the base or radix of this system is 10.

• e.g (23625)10 , (405)10 , (145.25)10


Decimal/ denary Number System
If we were to write out the digits of the denary number
“2493”, what is the value of each digit?
Power of 10
representation

i.e. each ‘1’ in this place


103 102 101 100 value is worth 1000.
This subscript means
1000 100 10 1 the number is in base
10. We don’t include it
multiply
2 4 9 310 if the base is obvious
from the context.

2x103 4x102 9x101 3x100

? +400
2000 ? +90
? + 3? = 2493
?
Decimal/ denary Number System
If we were to write out the digits of the denary number
“145.25”, what is the value of each digit?
Power of 10
representation

102 101 100 10-1 10-2


This subscript means
100 10 1 0.1 0.01 the number is in base
10. We don’t include it
multiply
1 4 5 . 2 510 if the base is obvious
from the context.

1x102 4x101 5x100 2x10-1 5x10-2

100 ? + ? 5 + 0.2
? + 40 ? + 0.05 ?
? = 145.25
Any Base → Denary
Now suppose we had a number in base 5 instead. How
do we convert it to denary?
In base 10, the place values
53 52 51 50 were powers of 10, i.e. 1,
10, 100, 1000. So in base 5,
we’d have powers of 5,
?
125 ?
25 5? 1? always starting with 1 on
the right.

4 3 0 15
4x53 3x52? 0x51 1x50

? + 0? + 1? = 576?
? + 75
500
Test Your Understanding
Convert the following to denary

8 4 ?2 1 64 16 ? 4 1

1 0 1 12 3 3 0 24
8 + 0 + ?2 + 1 = 11 192 + 48 + 0? + 2 = 242

27 9 ? 3 1

1 2 2 03
27 + 18 ?+ 6 + 0 = 51
Convert decimal to binary
Convert 56 to binary Convert 99 to binary
Binary
Quotient Remainder
99 ÷ 2 = 49 1
49 ÷ 2 = 24 1
24 ÷ 2 = 12 0
12 ÷ 2 = 6 0
6÷2 = 3 0
3÷2 = 1 0
1÷2 = 0 1
5610=1110002 9910=11000012
Convert decimal to octal
Convert 56 to octal Convert 99 to octal
Binary
Quotient Remainder
99 ÷ 8 = 12 3
12 ÷ 8 = 1 4

5610 = 708 9910 = 438


Binary Number System
• Base 2
• Two Digits: 0, 1
• Example: 10101102
• Positional Number System
n -1 4 3 2 1 0
2 2 2 2 2 2
bn -1  b4 b3 b2 b1 b0
• Binary Digits are called Bits
• Bit bo is the least significant bit (LSB).
• Bit bn-1 is the most significant bit (MSB).
Binary Number System

• nybble = 4 bits

• byte = 8 bits

• (short) word = 2 bytes = 16 bits

• (double) word = 4 bytes = 32 bits

• (long) word = 8 bytes = 64 bits

• 1K (kilo or “kibi”) = 1,024 bytes

• 1M (mega or “mebi”) = (1K)*(1K) = 1,048,576 bytes

• 1G (giga or “gibi”) = (1K)*(1M) = 1,073,741,824 bytes


Convert Binary Decimal

Convert the binary number 10101110 to decimal

Power of 2
27 26 25 24 23 22 21 20
representation
Decimal
128 64 32 16 8 4 2 1
representation
Base 2
1 0 1 0 1 1 1 0
representation

128 + 32 + 8 + 4 + 2 = 174
101011102 = 174
Convert Binary Decimal
Convert the binary number 10101110 to octal

First, convert given binary to decimal


128 + 32 + 8 + 4 + 2 = 174 à 101011102 = 174

Convert this decimal to octal form


Binary
Quotient Remainder
174 ÷ 8 = 21 6
21 ÷ 8 = 2 5
2 ÷8= 0 2

101011102 = 17410 = 2568


Example
Can you figure the decimal values for these binary values

a) 11 à3

b) 101 à5

c) 110 à6

d) 1111 à 15

e) 11011 à 27
Octal Number System

• The octal number system consists of 8 digits namely


0 to 7.
• Example: (76)8 , (55.25)8
Convert decimal to octal

Convert the decimal number 92 to octal


Decimal
Quotient Remainder
92 ÷ 8 = 11 4
11 ÷ 8 = 1 3
1 ÷8= 0 1

92 = 1348
Convert decimal to octal
Convert the binary number 1010.11 to octal

Power of 2
23 22 21 20 2-1 2-2
representation
Decimal
8 4 2 1 0.5 0.25
representation
Base 2
1 0 1 0 1 1
representation

8 + 2 + 0.5 + 0.25 = 10.75


(1010.11)2 = (10.75)10
Example
Can you figure the decimal values for these octal values

a) 21 à 17

b) 156 à 110

c) 270 à 184

d) 1164 à 628

e) 2105 à 1093
Hexadecimal Number System
• The Hexadecimal number system, popularly known as Hex system
has 16 symbols, therefore its base/radix in 16.

• The 16 symbols used in Hexadecimal system are

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

e.g (45)16 , (11A)16


Convert Hex to Decimal

Convert hex 7CF to decimal

7 = 7
C = 12
F = 15

7CF = (7 × 162) + (12 × 161) + (15 × 160)


= (7 × 256) + (12 × 16) + (15 × 1)
= 1792 + 192 + 15
= 1999
Convert Hex to Decimal
Convert hex 1DA6 to decimal

1 = 1
D = 13
A = 10
6 = 6

1DA6 = (1 × 163) + (13 × 162) + (10 × 161) + (6 × 160)

= (1 × 4096) + (13 × 256) + (10 × 16) + (6 × 1)


= 4096 + 3328 + 160 +6
= 7590
Convert Hex to Decimal
Convert hex E8B to decimal

E = 14
8 = 8
B = 11

E8B = (14 × 162) + (8 × 161) + (11 × 160)

= (14 × 256) + (8 × 16) + (11 × 1)


= 3584 + 128 + 11
= 3723
Example
Can you figure the decimal values for these hex values

a) 2A à 42

b) 15F à 351

c) A7C à 2684

d) 11BE à 4542

e) A10D à 41229
Convert Hex to Decimal
Convert binary 11011 to hexa
Binary à decimal à hexa
Binary à decimal
(11011)2 = ?16
1 x 24 +1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = (27)10

Decimal à hexa
Decimal
Quotient Remainder
27 ÷ 16 = 1 11
1 ÷ 16 = 0 1
1, 11 = 1B
Convert Hex to Decimal
Convert hexa A59C to decimal
Hexa à decimal
Hexadecimal to Denary
Multiples
of 16:
Convert the following from
0: 0
hexadecimal to denary:
1: 16 (a) 34 (b) A3
2: 32
3: 48
4: 64
5: 80 16 1 16 1
6: 96
7:
8:
9:
112
128
144
3 4
?a 10 ?3b
A:
B:
160
176 48 +4 = 52 160 +3 = 163
C: 192
D: 208
E: 224
F: 240
Test Your Understanding
Multiples
of 16:
Convert 8C from hexadecimal to
0: 0
denary.
1: 16
2: 32
3:
4:
48
64
16 1
5:
6:
7:
80
96
112
8 12?
8:
9:
A:
128
144
160
128 +12 = 140
B: 176
C: 192
D: 208
E: 224
F: 240
Denary to Hexadecimal
We can use exactly the same method as we did for denary to
Multiples any general base…
of 16:
Convert 183 from denary to hexadecimal.
0: 0
1: 16
2: 32
3: 48 16 1
4: 64
5:
6:
80
96
B? 7?
7: 112
8:
9:
128
144
176 + 7 = 183
A: 160
B: 176
C: 192 What is the most number of 16s we can use to make
D: 208 up 183? The table on the left will be very handy!
E: 224
F: 240
Test Your Understanding
Multiples Convert 78 from denary Convert 234 from denary
of 16: to hexadecimal. to hexadecimal.

0: 0
1: 16 16 1 16 1
2: 32
3:
4:
48
64 4 ? E E ? A
5: 80
6:
7:
96
112
64 + 14 =84 224 + 10 =234
8: 128
9: 144
A: 160
B: 176
C: 192
D: 208
E: 224
F: 240
Hexadecimal to Binary
We already have methods to convert from denary to other bases, and other
bases to denary. We could therefore convert via denary.

Convert 5A from hexadecimal to binary.

Convert to denary first: 16 1

5 10 ?
80 + 10 = 90
Then convert from denary to binary:

64 32 16 8 4 2 1

1 0 1 1 ?0 1 0
64 +16+8 +2 = 90
Hexadecimal to Binary
Convert 5A from hexadecimal to binary.

But a nice little trick to convert each digit separately (noting that each
hexadecimal digit requires 4 bits, i.e. a nibble), and then to concatenate the
results together.

5 in binary à 0101 ?
A = 10 in binary à 1010 ?

Therefore 5A in binary à 0101 1010


?
Further Example
Convert B9 from hexadecimal to binary.

B = 11 in binary à 1011 ?
9 in binary à 1001 ?

Therefore B9 in binary ?
à 10111001
Test Your Understanding
Convert 6F from hexadecimal to binary.

6 in binary à 0110 ?
F in binary à 1111 ?

Therefore 6F in binary ?
à 01101111
Binary Addition

Rule for Binary Addition:

0+0=0
0+1=1
1+0=1
1 + 1 = 0 (Carry 1)
Conversion between bases
To convert from one base to another:

1) Convert the Integer Part


2) Convert the Fraction Part
3) Join the two results with a radix point
Conversion between bases

• To Convert the Integral Part:


Repeatedly divide the number by the new radix and save
the remainders. The digits for the new radix are the
remainders in reverse order of their computation. If the
new radix is > 10, then convert all remainders > 10 to
digits A, B, …
• To Convert the Fractional Part:
Repeatedly multiply the fraction by the new radix and
save the integer digits that result. The digits for the new
radix are the integer digits in order of their computation.
If the new radix is > 10, then convert all integers > 10 to
digits A, B, …
Conversion between bases
Convert 4 6. 6 8 7 510 to binary (base 2)

Convert 46 to Base 2 Convert 0.6875 to Base 2


46/2 = 23 rem 0 0.6875 x 2 = 1.3750 int = 1
23/2 = 11 rem 1 0.3750 x 2 = 0.7500 int = 0
11/2 = 5 rem 1 0.7500 x 2 = 1.5000 int = 1
5/2 = 2 rem 1 0.5000 x 2 = 1.0000 int = 1
2/2 = 1 rem 0 0
1/2 = 0 rem 1

Reading remainders in reverse: Reading int portion in forward


1011102 direction: 0.10112

Join the results together with the radix point: 101110.10112


Convert decimal to octal
Convert the decimal number 10.75 to octal

Multiply the fractional part


repeatedly by 8 until it
becomes 0.
Whole number Fractional
Quotient Remainder
10 ÷ 8 = 1 2 0.75 x 8 = 6 0
1 ÷8= 0 1

10.7510 = 12.68
Conversion between bases
Convert 5 6. 8 9 10 to octal (base 8)

Convert 56 to Base 8 Convert 0.89 to Base 8


56/8 = 7 rem 0 0.89 x 8 = 7.12 7 0.12
7/8 = 0 rem 7 0.12 x 8 = 0.96 0 0.96
0.96 x 8 = 7.68 7 0.68
0.68 x 8 = 5.44 5 0.44
0.44 x 8 = 3.52 3 0.52
Reading remainders in reverse: 708 0.52 x 8 = 4.16 4 0.16
0.16 x 8 = 1.28 1 0.28
0.28 x 8 = 2.24 2 0.24
………

0.8910 : 0.70753412…8

Join the results together with the radix point: 70.70753412...8


Conversion between bases
Convert 51966. 3125 10 to hexadecimal (base 16)

Convert 56 to Base 16 Convert 0.3125 to Base 16


51966/16 = 3247 R 14 0.3125 x 16 = 5.0 5 0.0
3247/16 = 202 R 15 0
202/16 = 12 R 10
12/16 =0 R 12

12 10 15 14
0.322510 : 0.516
Reading remainders in reverse: CAFE16

Join the results together with the radix point: CAFE.516


Conversion between bases
Convert 51966. 3125 10 to hexadecimal (base 16)

Convert 56 to Base 16 Convert 0.3125 to Base 16


51966/16 = 3247 R 14 0.3125 x 16 = 5.0 5 0.0
3247/16 = 202 R 15 0

202/16 = 12 R 10
12/16 =0 R 12

12 10 15 14 0.322510 : 0.516

Reading remainders in reverse: CAFE16

Join the results together with the radix point: CAFE.516


Test Your Understanding
Convert the following decimal:

11.7510 to binary

9.62510 to binary

62.510 to octal

106.4510 to octal

36.812510 to hexadecimal

3162.562510 to hexadecimal
Test Your Understanding

11.7510 to binary

Whole number Fractional


Quotient Remainder
11 ÷ 2 = 5 1 0.75 x 2 = 1 5
5 ÷2= 2 1 0.5 x 2 = 1 0
2 ÷2= 1 0 0
1 ÷2= 0 1

1110 = 10112 0.7510 = 112

11.7510 = 1011.112
Test Your Understanding

9.62510 to binary

Whole number Fractional


Quotient Remainder
9÷2= 4 1 0.625 x 2 = 1 25
4 ÷2= 2 0 0.25 x 2 = 0 5
2 ÷2= 1 0 0.5 x 2 = 1 0
1 ÷2= 0 1 0

910 = 10012 0.62510 = 1012

9.62510 = 1001.1012
Test Your Understanding

62.510 to octal

Whole number Fractional


Quotient Remainder
62 ÷ 8 = 7 6 0.5 x 8 = 4 0
7 ÷8= 0 7 0

6210 = 768 0.510 = 0.48

9.62510 = 76.48
Test Your Understanding
106.4510 to octal

Whole number Fractional


Quotient Remainder
106 ÷ 8 = 13 2 0.45 x 8 = 3 6
13 ÷ 8 = 1 5 0.6 x 8 = 4 8
1 ÷8= 0 1 0.8 x 8 = 6 4
0.4 x 8 = 3 2
0.2 x 8 = 1 6
10610 = 1528 0.6 x 8 = 4 8
0.8 x 8 = 6 4

0.4510 = 0.3463146…8
106.4510 = 152. 3463146…8
Test Your Understanding
36.812510 to hexadecimal

Whole number Fractional


Quotient Remainder
36 ÷ 16 = 2 4 0.8125 x 16= 13 0
2 ÷ 16 = 0 2 0

3610 = 2416 0.812510 = 0.1316


0.812510 = 0.D16

36.812510 = 24.D16
Test Your Understanding
3162.562510 to hexadecimal

Whole number Fractional


Quotient Remainder
3162 ÷ 16 = 197 10 0.5625 x 16 = 9 0
197 ÷ 16 = 12 5 0
12 ÷ 16 = 0 12

316210 = 12 5 1016 0.812510 = 0.916


316210 = C 5 A16

3162.562510 = C5A.916
Binary Addition-Example

Add 110101 and 101111

1 1 0 1 0 1
1 0 1 1 1 1
1 1 0 0 1 0 0
Binary Addition-Example

Add 10110 and 1101

1 0 1 1 0

0 1 1 0 1

1 0 0 0 1 1
Adding in binary

1 0 0 1
+ 1 1 0 1
1
?e 0
?d 1
?c 1
?b 0
?a

1 1
Further Example

1 0 1 0
+ 1 1 0 1 1
1 0
?f ?e 0
?d 1
?c 0
?b 1
?a

1 1
Test Your Understanding

1 1 0 1
+ 1 1 1
1 0 1? 0 0

1 0 0 1
+ 1 0 1 1
1 0 1? 0 0
Review
1 Convert 71 from denary to binary 2 Add the binary numbers:
11010 + 1111

64 32 16 8 4 2 1

1 1 0 1 0
1 0 0
?
0 1 0 1
+ ? 1 1 1 1
1 0 1 0 0 1

You might also like