COMS1015 Data Representation A
COMS1015 Data Representation A
Byte 8 bits
32-bit machines
64-bit machines
5
Analog data obtained from the real world is
continuous
Digital data as represented in digital
computers is discrete
Analog data is converted to digital data by
sampling it at a finite number of points. The
data at these points are stored in binary
format.
Important facts about electronic signals
An analog signal continually fluctuates in
voltage up and down
A digital signal has only a high or low state,
corresponding to the two binary digits
All electronic signals (both analog and digital)
degrade as they move down a line
The voltage of the signal fluctuates due to
environmental effects
Periodically, a digital signal is reclocked to
regain its original shape
Figure 3.2
An analog and a digital
signal
Figure 3.3
Degradation of analog and digital signals
8
Not only numbers, but any data can be
represented by binary numbers
11
Using two decimal digits:
let 1 through 49 represent 1 through 49
let 50 through 99 represent -50 through -1
12
To perform addition, add the numbers and
discard any carry into the hundreds position
Now you try it
48 (signed-magnitude)
-1
47
13
A-B=A+(-B)
Add the negative of the second to the first
Try
4 -4 -4
-3 +3 + -3
14
Formula to compute the negative
representation of a number
15
Two’s Complement
(Vertical line is easier to read)
16
Addition and subtraction are the same as in
10’s complement arithmetic
-127 10000001
+ 1 00000001
-126 10000010
17
• Working out 2s complements:
• For example, for 8 bits, if we want to
represent –x we would use 28 – x
• That is 100000000-x
• Rather write this as 11111111 - x + 1
because the first two terms are “flip the bits
of x”
Rule: Flip the bits of x and add 1!
-32 -00100000 11011111+1 11100000
-64 -01000000 10111111+1 11000000
-96 -01100000 10100000
19
What happens if the computed value won't
fit?
Overflow
If each value is stored using eight bits,
adding 127 to 3 overflows
01111111
+ 00000011
10000010
20
A real value in base 10 can be defined by the
following formula
21
5 digit mantissa examples
15556*104
A binary floating-point value is defined by the formula
sign * mantissa * 2exp
22
What must be provided to represent text?
There is a finite number of characters to
represent, so list them all and assign each a
binary string
Character set
A list of characters and the codes used to
represent each one
Computer manufacturers agreed to
standardize…
23
ASCII stands for American Standard Code for
Information Interchange
ASCII originally used seven bits to represent
each character, allowing for 128 unique
characters
Later extended ASCII evolved so that all eight
bits were used
How many characters could be represented?
24
25
The first 32 characters in the ASCII
character chart do not have a simple
character representation to print to
the screen
26
Extended ASCII is not enough for international
use
Unicode uses 16 bits per character
How many characters can UNICODE
represent?
Unicode is a superset of ASCII
The first 256 characters correspond exactly to
the extended ASCII character set
27
Figure 3.6 A few characters in the Unicode character set
28
• Data compression
Reduction in the amount of space needed to
store a piece of data
• Compression ratio
The size of the compressed data divided by
the size of the original data
• A data compression technique can be
– lossless, which means the data can be retrieved
without any loss of the original information
– lossy, which means some information may be lost
in the process of compaction
Assigning 16 bits to each character in a
document uses too much file space
30
A single character may be repeated over and
over again in a long sequence
Replace a repeated sequence with
◦ a flag character
◦ repeated character
◦ number of repetitions
*x8
◦ * is the flag character
◦ x is the repeated character
◦ 8 is the number of times x is repeated
31
Original text
bbbbbbbbjjjkllqqqqqq+++++
Encoded text
*b8jjjkll*q6*+5 (Why isn't l encoded? J?)
The compression ratio is 15/25 or .6
Encoded text
*x4*p4l*k7
Original text
xxxxpppplkkkkkkk
This type of repetition doesn’t occur in English text; can you
think of a situation where it might occur?
32