Data Representation

Download Report

Transcript Data Representation

What is a computer?
A computer is a device that:
– Accepts input
– Processes data
– Stores data
– Produces output
Let’s examine components in
more detail…
What is a computer?
A computer is a device that:
– Accepts input: Input devices
Name as many as you can:
What is a computer?
A computer is a device that:
– Accepts input: Input devices
Name as many as you can:
Keyboard, mouse,
scanner, bar code
reader, light pen, infrared sensor,
video camera and many more…
What is a computer?
A computer is a device that:
– Processes data: Processors
Name as many as you can:
What is a computer?
A computer is a device that:
– Processes data: Processors
Name as many as you can:
CPU, graphics processor, video controller, modem,
and many more…
What is a computer?
A computer is a device that:
– Stores data: Storage devices
Name as many as you can:
What is a computer?
A computer is a device that:
– Stores data: Storage devices
Name as many as you can:
Main memory, hard drive, CD-ROM, DVD-ROM,
memory card, tape drive, ZIP disk, floppy disk,
What is a computer?
A computer is a device that:
– Produces output: Output devices
Name as many as you can:
What is a computer?
A computer is a device that:
– Produces output: Output devices
Name as many as you can:
Monitor, printer, speaker, indicator light, and many
more…
Data Representation
A computer is a device
that:
– Accepts input
– Processes data
– Stores data
– Produces output
Input data transformed into
output.
Data can be stored for
Data Representation
Spreadsheet data  graphs
3D models  animation
Vocals and MIDI  Song
Bar code  Price of item
Card and Pin #  Money
Data Representation

How can we represent information in a
way that can be stored and
manipulated by a computer?
Data Representation and
Storage


External representation: computers
use decimal digits (base ten), 26character alphabet for easier human
interaction via keyboard, terminal,
printer
Internal representation: computers
use binary system for numbers,
letters, graphics, etc.
Data Representation



Internally, computers represent
information as patterns of bits
A bit (binary digit) is either 0 or 1;
these are symbols and have no
numeric meaning
Storing a bit requires that a device can
be in one (and only one) of just two
states; analogous to true and false
Bit Storage

Why only two states? Why not use ten
states to correspond with the base ten
numbering system?
Data Representation
Binary Numbers!!!
Sound  pitch  number  binary number
Letter  number  binary number
Image  color at each pixel  number  binary
number
Decimal Number Systems



Base 10
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
e.g. 34210 =
= 3 x 102 + 4 x 101 + 2 x100
= 3 x 100 + 4 x 10 + 2 x
1
= 300
+ 40
+2
Binary Number System



Base 2
Digits 0, 1
e.g. 1102 =
= 1 x 22 + 1 x 21 + 0 x 20
= 1x4
+1x2
+0x1
= 4
+2
+0
= 6
Counting in Binary
Decimal
0
1
2
3
4
5
Binary
0
1
10
11
100
101
Decimal
6
7
8
9
10
11
Binary
110
111
1000
1001
1010
1011
Place and value




In a decimal number, each place value is
10 times greater than the place to its
right.
In a binary number, each place value is 2
times greater than the place to its right.
For convenience, we group every four
binary bits into a hexdecimal digit (1-9,
A,B,C,D,E,F)
In a hexdecimal number, each place value
is 16 times greater than the place to its
right.
Binary Numerals

01101101
– Bits are numbered from the right
b7 b6b5b4b3b2b1b0
– Subscripts represent the place value

bi has place value 2i
– Convert to decimal

b7 * 27+b6*26 + b5*25 +b4*24 +b3*23 +b2*22
+b1*21 + b0*20
Data Representation

100
= 1 * 22 + 0 * 21 + 0
10
= 1 * 21 + 0
1
Data Representation

Binary to Decimal
10011
= 1 * 24 + 0 * 23 + 0 * 22 + 1* 21 +
1 * 20
Data Representation

Binary to Decimal
10011
= 1 * 24 + 0 * 23 + 0 * 22 + 1* 21 +
1 * 20
= 16
+0
+0
+ 2
+1
= 19
Excercise

1011b = ?d
Addition


1000 + 1 =?
0011 + 0010 =
4 bits and Hex
– 0000
;0
– 1000
;8
– 0001
;1
– 1001
;9
– 0010
;2
– 1010
;10 (Ah)
– 0011
;3
– 1011
;11 (Bh)
– 0100
;4
– 1100
;12 (Ch)
– 0101
;5
– 1101
;13 (Dh)
– 0110
;6
– 1110
;14 (Eh)
– 0111
;7
– 1111
;15 (Fh)
Converting Binary to
Decimal


Another method: repeatedly multiply by
2 and add next bit
e.g. 110101
0x2= 0+1= 1
1x2= 2+1= 3
3x2= 6+0= 6
6 x 2 = 12 + 1 = 13
13 x 2 = 26 + 0 = 26
26 x 2 = 52 + 1 = 53
Converting Decimal to
Binary


Repeatedly divide by 2, recording
remainders in reverse order
e.g. 53 / 2 = 26 R 1
26 / 2 = 13 R 0
13 / 2 = 6 R 1
6/2= 3R0
3/2= 1R1
1/2= 0R1
giving 110101
Data Representation
use a fixed number of digits.
But how many bits do we need?
1 binary digit 
2 binary digits 
3 binary digits 
101, 110, 111 
0 or 1  2 possible chars
00, 01, 10, 11  4 chars
000, 001, 010, 011, 100,
8 chars
Data Representation
Solution: use a fixed number of digits.
But how many bits do we need?
1 binary digit  0 or 1  2 possible chars
2 binary digits  00, 01, 10, 11  4 chars
3 binary digits  000, 001, 010, 011, 100, 101, 110, 111
 8 chars
Notice a pattern? 12, 24, 38, …
the total number of character that can be represented by n
bits is
2n
Number of bits


How many states can be represented
with 1 bits, 2 bits, 3 bits, 8 bits ….
To represent N states, how many bits
are needed.
Data Representation
But how many bits are needed to store n symbols?
Or, how many bits are needed to represent n
numbers?
log2n
Character Representation




1 byte = 8 bits = 1 character?
256 possible codes with 8 bits
Assign a character to each code
Common assignment
– ASCII - American Standard Code for
Information Interchange – defines first
128
ASCII Code
Code Value
Letter
0
Null character
1 - 31
Special Control
Characters
10
\n = New line
32
Space
33-47, 58-64, 91-96 Punctuation
48 - 57
0-9
65 - 90
A-Z
Interesting ASCII Choice?

Digits 0 through 9 seem strange?
Digit
Dec
Hex
0
48
30
1
49
31
…
…
…
9
57
39
Data Representation

American Standard Code for Information
Interchange (ASCII ) defines 256 symbols that can
be stored in a byte. Each symbol corresponds to a
number from
Symbol
Decimal
Binary
0 -- 255
@
64
01000000
A
65
01000001
B
66
01000010
C
67
01000011
D
68
01000100
E
69
01000101
F
70
01000110
G
71
01000111
H
72
01001000
Unicode



International language coding
standard
Superset of ASCII
Various codes defined to use upper
128 bits for symbols and other
languages
Memory Sizes




Byte = 8 bits
Kilobyte (K)
= 210 = 1,024 bytes
Megabyte (Mb) = 220 = 1,048,576 bytes
Gigabyte (Gb) = 230 = 1,073,741,824
bytes
16-bit Memory Word



To store number 6, use
0000000000000110
Value 0 is 0000000000000000
Largest value is
1111111111111111 = 65,535 = 216 −
1