02-Data Representation View
02-Data Representation View
Data Representation
DCS201- Computer Science
By:
Dilum Bandara
CSE
2
Outline
p Terminology & measuring data
p Data representation
n Quantitative, Qualitative
p Quantitative Data
n Different number systems
p Decimal, binary, octal, hexadecimal
n Number base conversion
n Representing sign numbers
p Qualitative data
n ASCII, EBCDIC, Unicode
CSE
3
Terminology
p Computers store & process data
p Data is anything that has some interest to the
user
p Thoughtfully processed data is called information
p Physical devices used to store & process data in
computers are 2-state devices
p State is represented using;
n 0 OFF
n 1 - ON
CSE
4
Bit & Byte
p An abbreviation for BInary digiT
p Bit is the smallest unit of data
representation
p When 8 bits are combined together it is
called a byte
p 1024 (2
10
) bytes are called a Kilobyte
CSE
5
Terminology
p Computers represent numbers as a series
of switches which store a pattern of ON's &
OFF's, representing the binary digits 1 & 0.
p Each of these digits is called a BIT (BInary
digiT)
1 0 1 1 0 0 1 1
6 5 4 3 2 1 0 7
CSE
6
Terminology cont
1 0 1 1 0 0 1 1
6 5 4 3 2 1 0 7
LSB Least
Significant Bit
MSB Most
Significant Bit
CSE
7
Metrics used to measure quantities
of data
-
125,000 1000 Kilobits
Mb Megabit
-
125 1000 bits
Kb Kilobit
2
40 1,099,511,627,776 1024 Gigabyte
TB Terabyte
2
30 1,073,741,824 1024 Megabytes
GB Gigabyte
2
20 1,048,576 1024 Kilobytes
MB Megabyte
2
10 1024 1024 Bytes
KB Kilobyte
2
0 1 8 bits
Byte Byte
-
-
Bit Bit
Power of 2 Bytes Symbol Abbreviation
CSE
8
Data representation
Data
Representation
Represents quality or
characteristics
Not proportional to a value
Name, NIC no, index no,
Address
Quantifiable
Proportional to value a
Number of students, marks
for DCS201
Qualitative
Quantitative
CSE
9
Quantitative data
10
Number Systems
CSE
11
Humans vs. Computers
p It is not surprising that our number
system is based on units of TEN,
n Since nature provided man with five fingers on
each of 2 hands.
p Computers use binary
n They have only electronic or electromechanical
switches.
n These switches have only 2 states, either ON
or OFF
CSE
12
Distinguishing Number Systems
p The characteristic which distinguish one
number system from another is called the
base (or radix)
p The base or radix, of a number system is:
n the number of different digits that can occur in
each position in the number system.
n this is the number of symbols in a system
n Example: Base 10 - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
CSE
13
Number Bases
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A,
B, C, D, E, F
16
Hexadecimal
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 10 Decimal
0, 1, 2, 3, 4, 5, 6, 7 8 Octal
0, 1 2 Binary
Symbols Base Number
System
CSE
14
Decimal Number System
p The number 4567 in base 10 means:
4567 = four thousand five hundred and sixty seven
= 4000 + 500 + 60 + 7
= (4 1000) + (5 100) + (6 10) + (7 1)
= (4 10
3
) +(5 10
2
) +(6 10
1
)+(7 10
0
)
CSE
15
Positional notations
p In general, the relationship between a
digit, its position & the base of the number
system is expressed by the following
formula:
DIGIT BASE
POSITION #
CSE
16
Weight Associated with Digit Position
When expressed as a series of digits, the
value of a number is determined by
considering the "weight" associated with
the position of each digit.
CSE
17
p The number 512.49 in base 10 means:
512.49 = 500 + 10 + 2 + 0.40 + 0.09
= (5100)+(110) + (21) + (4 0.1)+
(9 0.001)
= (510
2
) + (110
1
) + (210
0
) + (4 10
-1
) +
(9 10
-2
)
CSE
18
Binary number system
p Base of the binary number system is 2
p Symbols are 0 & 1
p The number 1101.11 in base 2 means:
1101.01
= (12
3
)+(12
2
)+(02
1
)+(12
0
)+(02
-1
)
+ (12
-2
)
CSE
19
Octal number system
p Base of the octal number system is 8
p The symbols are 0, 1, 2, 3, 4, 5, 6 & 7
p The number 456.41 in base 8 means:
475.01
=(48
2
)+(78
1
)+(58
0
)+(08
-1
)+(1 8
-2
)
CSE
20
Hexadecimal number system
p The base is 16
p The symbols are
n 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
p The number 1FA.4C in base 16 means:
1FA.4C
=(116
2
)+(F16
1
)+(A16
0
)+(416
-1
)
+(C16
-2
)
= (116
2
)+(1516
1
)+(1016
0
)+(416
-1
)
+(1216
-2
)
CSE
21
Number Base Conversion
p It is necessary to convert from one
number system to another
p Example:
n Windows Calculator
CSE
22
Decimal to Binary conversion - Integers
pConvert 9
10
into binary
9/2 = 4 r = 1
4/2 = 2 r = 0
2/2 = 1 r = 0
1/2 = 0 r = 1
p9
10
= 1001
2
CSE
23
Decimal to Binary conversion cont
p Convert 27
10
to binary
p27
10
= 11011
2
CSE
24
Decimal to Binary Fractions
p Example 1: Represent 0.5
10
in binary
0.52 = 1.0
0.02 (this ends the process)
So 0.5
10
= 0.1
2
p Example 2: Represent 0.1
10
in binary
n 0.1
10
= 0.000110011001
2
n =
1101 0001 . 0
CSE
25
Binary to Decimal conversion - Integers
p Example 3: Convert 11101.01
2
to decimal
p We will calculate the position value for
each binary digit & then sum theoe values
p We write the position values above each
digit.
2
4
2
3
2
2
2
1
2
0
2
-1
2
-2
Position
Values
16 8 4 2 1 0.5 0.25
Binary Digits 1 1 1 0 1 . 0 1
CSE
26
Example 3: cont
p 11101.01
= (12
4
)+(12
3
)+(12
2
)+(0 2
1
)+(12
0
)
+(02
-1
)+(12
-2
)
= (116)+(18)+(14)+(02)+(11)
+(00.5) +(10.25)
= 16+8+4+0+1+0+0.25
= 29.25
CSE
27
Example 4:
p Convert 111001
2
to decimal
p 111001
2
= 57
10
CSE
28
Decimal to Octal conversion
p Represent 31
10
in octal
31/8 = 3 r = 7
3/8 = 0 r = 3
p31
10
= 37
8
CSE
29
Decimal to Hexadecimal conversion
p Represent 31
10
in hexadecimal
31/16 = 1 r = 15
1/16 = 0 r = 1
p31
10
= 1F
16
CSE
30
Example 4:
p Represent 1234
10
in hexadecimal
p 1234
10
= 4D2
16
CSE
31
Binary to Octal conversion
p Example 6: convert 11010011
2
in to octal
11 | 010 | 011
011 | 010 | 011 - add extra bit
3 2 3
11010011
2
= 323
8
CSE
32
Binary to Hexadecimal conversion
p Convert 10011101 into hexadecimal
1001 | 1101
9 13
9 D
10011101
2
= 9D
8
CSE
33
Octal to hexadecimal conversion
p Convert 37
8
to hexadecimal
3 7
011 111
011111
01 | 1111
0001| 1111
1 15
1 F = 1F
16
34
Representing Quantitative Data
CSE
35
Data representation in computers
p Data is stored as Registers
p Register is a series of switches
p Registers are limited in size
n So number of bits are limited
n-1 n-2 ... ... 2 0 1
n-bits
Min value - 0
Max value - 2
n
-1
CSE
36
Unsigned Integers
p Only the positive numbers
p With a single byte (8-bits)
n We can denote 2
8
(256) numbers
n 0 (00000000
2
) is the minimum
n 255 (11111111
2
) is the maximum
CSE
37
Binary addition
p In order to perform arithmetic operations
all operands should be in the same
number base
p Example:
n Add 01010
2
and 10001
2
n Answer = 11011
2
CSE
38
Example
p Add 111110
2
and 11000111
2
n You are given only 8-bit registers
111110 00111110
11000111 + 11000111 +
100000101 00000101
Carry bit
Overflow
CSE
39
Binary Subtraction
p Example :
Subtract 11110 from 11000111
CSE
40
Binary multiplication
p Example: Multiply 1110 and 1011
CSE
41
Binary Division
p Example: Divide 1110 by 10
CSE
42
Signed Integers
p Denote whole numbers with are both
positive & negative
p Representing sign integers
n Sign & Magnitude method (S&M)
n Bias notation
n Complement method
CSE
43
Sign & Magnitude method (S&M)
p MSB represents the sign
p Remaining bits represents the magnitude
p If S (sign)
n 0 - the integer is positive or zero
n 1 - the integer is negative or zero
sign n-1 ... n-2 ... 2 0 1
Magnitude (n-bits)
CSE
44
S&M cont
pWith a (n+1) bit register
pn
th
bit represent the sign
pNumber range
n Min number = -(2
n
-1)
n Max number = +(2
n
-1)
n If (n+1)=8-bits find the number range
CSE
45
Example
p Represent -11
10
in S&M method
p Always assume 8-bit regisers
p 11
10
= 1011
2
= 0001011
2
Since number is negative S=1
10001011
CSE
46
Sign & Magnitude cont
p Examples
n Bit pattern decimal value
0000 0001 +1
1000 0001 -1
0111 1111 +127
1111 1111 -127
0000 0000 +0
1000 0000 -0
CSE
47
Sign & Magnitude cont
p Advantages
n Sign reversal
n Finding the absolute value (|a|)
p Disadvantage
n Adding a negative of a number is not the same
as subtraction.
p Need different operations
n Zero is no unique
48
Representing Qualitative Data
CSE
49
Character representation
p Belong to the category of qualitative data
p Represent quality or characteristics
p Also called non-numeric values
p Includes
n Letters - a-z, A-Z
n Digits - 0-9
n Symbols - !, @ , *, /, &, #, $
n Control characters - <CR>, <BEL>, <ESC>,
<LF>
CSE
50
Character representation cont
p With a single byte (8-bits) 256 characters
can be represented
p Standards
n ASCII - American Standard Code for
Information Interchange
n EBCDIC - Extended Binary-Coded Decimal
Interchange Code
n Unicode
CSE
51
ASCII
p De facto world-wide standard for the code
numbers used by computers to represent:
n upper & lower-case Latin letters
n Numbers
n Punctuations
p There are 128 standard ASCII codes
n Can be represented by a 7 digit binary
number: 000 0000 through 111 1111
CSE
52
ASCII table
NUL
SOH
STX
ETX
EOT
ENQ
ACK
BEL
BS
TAB
LF
VT
FF
CR
SO
SI
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Symbol Hex
ASCII
(space)
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/
20
21
22
23
24
25
26
27
28
29
2A
2B
2C
2D
2E
2F
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Symbol Hex ASCII
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
30
31
32
33
34
35
36
37
38
39
3A
3B
3C
3D
3E
3F
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Symbol Hex ASCII
CSE
53
ASCII table cont
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
40
41
42
43
44
45
46
47
48
49
4A
4B
4C
4D
4E
4F
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Symbol Hex ASCII
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
50
51
52
53
54
55
56
57
58
59
5A
5B
5C
5D
5E
5F
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Symbol Hex ASCII
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
60
61
62
63
64
65
66
67
68
69
6A
6B
6C
6D
6E
6F
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Symbol Hex ASCII
CSE
54
ASCII - things to note
p ASCII codes for digits are not equal to the
numeric value
p A simple code set & supported by almost
every computer
p But, most languages need more than 128
characters
CSE
55
EBCDIC
p Use 8-bits
p Used by large IBM computer (main
frames)
p Note
n IBM PC uses only ASCII
CSE
56
Unicode www.unicode.org
p Is designed to overcome the limitation of number
of characters
p Assigns unique character codes to characters in a
wide range of languages.
p A 16-bit character set
p 65,536 (2
16
) distinct Unicode characters
p Unicode provides a unique number for every character,
no matter what the platform,
no matter what the program,
no matter what the language.
CSE
57
Unicode cont
p Even
supports
Sinhala &
Tamil
Courtesy by Unicode.org
CSE
58
Summary
pData, Information
pQuantitative & qualitative data
pNumber systems
n Binary, octal, decimal & hexadecimal
pNumber base conversion
pSigned & unsigned integers
pMathematical operations with binary
pCharacter coding
n ASCII, EBCDIC, Unicode