Data Representation

Download Report

Transcript Data Representation

Data Representation
How is data stored on a computer?
Registers, main memory, etc. consists of
grids of transistors
Transistors are in one of two states, on or
off
Each transistor can represent one digit in
a base 2 (binary) number
All data must be converted to this form
before it is stored in memory
Numeric (integer) data
There are straightforward algorithms to convert
integers in decimal and other bases to binary
One bit is reserved to represent the sign of the
number (signed magnitude representation)
Examples in 8 bits:
4710 = 001011112
-4710 = 101011112
Hexadecimal Representation
Decimal is relatively difficult to convert
because the decimal digits of the number
don't match up with groups of bits in the
binary representation
Base 8 (octal) and base 16 (hexadecimal)
are easier because each digit corresponds
to 3 or 4 bits in the binary representation.
The hexadecimal number system
Decimal
Hex
Binary
Decimal
Hex
Binary
0
0
0000
8
8
1000
1
1
0001
9
9
1001
2
2
0010
10
A
1010
3
3
0011
11
B
1011
4
4
0100
12
C
1100
5
5
0101
13
D
1101
6
6
0110
14
E
1110
7
7
0111
15
F
1111
Example
10110000100101110110001011111101
B
0
9
7
6
2
F
D
Uses:
HTML – representing color strings
#FFCCFF
First two digits are red component, next two are green, final two are blue
HTML character entities
&#169 is the character entity for the copyright symbol
Numeric (decimal) data
We also need to store numbers like
239.23
Like integers, there are a set number of
bits that are used to represent decimal
numbers
To simplify the problem, we use scientific
notation: 239.23 = 2.3923 x 103 (except in
binary)
IEEE Floating Point Format
mantissa – the significant digits of the number, normalized so that there is one
digit to the left of the decimal point (binary point, in this case) (also called
"significand")
exponent – power to which the mantissa is raised to get the original value
sign bit – 0 for positive numbers, 1 for negative numbers
Numeric representation Gotchas
Computers use a finite number of bits to
store numeric data
Some numbers are too big (or small) to fit
in the available number of bits – overflow
(or underflow)
How many places after the decimal does
1/3 have? How about pi? Floating point
representations are APPROXIMATIONS!
Textual Data
How would you store "siphonapterology" in
a computer's memory?
Textual Data
How would you store "siphonapterology" in
a computer's memory?
We must find a way to encode the
characters as numbers
Textual Data
How would you store "siphonapterology" in
a computer's memory?
We must find a way to encode the
characters as numbers
ASCII – a simple encoding for the Latin
alphabet, uses 7 bits per character, each
character fits into one byte.
Textual Data
How would you store "siphonapterology" in
a computer's memory?
We must find a way to encode the
characters as numbers
ASCII – a simple encoding for the Latin
alphabet, uses 7 bits per character, each
character fits into one byte.
Unicode – 16 bits per character,works for
more complex character sets
Images
Divided into squares called pixels
Each pixel is represented by a number
The number encodes the color used to display that
pixel
Programs?
Programs must be stored in memory, too
Every computer type has a "machine
language instruction set"
Each instruction has a binary code
10110000100101110110001011111101
What is it?
A 32 bit negative integer value?
A 32 bit negative floating point number?
Four characters in ASCII encoding?
Two characters in Unicode?
Pixels from an image?
Samples from a sound file?
An instruction from a program?
It depends – on how the value is used in
the execution of a program.