Title: Data Representation What Will We Cover
1Data Representation - What Will We Cover?
- Other number bases
- binary
- Representation of numbers
- integer
- 2s Complement
- floating point
- Integer and floating point arithmetic
- Representation of characters using code
2Data Representation
- Many different types of data
- integer (whole numbers)
- floating point (allows fractions)
- character data (text strings)
- Data types are often organised into data
structures such as
- arrays
- records
- files
- All data is represented by bit patterns
interpretation of which vary depending on the
type of data
3Number Systems - Decimal
- The decimal system is a base-10 system. There are
10 distinct digits (0 to 9) to represent any
quantity.
- For an n-digit number, the value that each digit
represents depends on its weight or position. The
weights are based on powers of 10.
POSITION
4TH.
3RD.
2ND.
1ST.
WEIGHT
103 1000
102 100
101 10
100 1
For example, 491610 41000 9100 110 61
4Number Systems - Binary
- The binary system is a base-2 system. There are 2
distinct digits (0 and 1) to represent any
quantity.
- For an n-digit number, the value that each digit
represents depends on its weight or position. The
weights are based on powers of 2.
For example 110100102 1128 164 032
116 08 04 12 0
1 21010
5Why use Binary?
- It is a two state systems (on/off) which makes it
simple to operate
- Even if degradation of current occurs (ie a
slight drop in voltage) it will still be detected
as a 1
- There are only four rules for addition in binary
compared to 100 in decimal
- 000 011 101 1110
6 Decimal to Binary Conversions
- To convert from decimal to a different number
base such as Binary involves repeated division by
the number 2
- Keep dividing until the quotient (body) is zero
- Use the remainders in reverse order
Decimal to Binary To
convert 69 to binary
269 à 1
234 à 0
217 à 1
28 à 0
1000101
24 à 0
22 à 0
21 à 1
7Numeric Data Types
- All machine languages include numeric data types
- Two types of numeric data are common in
computers
- integer
- floating point
- Integer and floating point representations are
the most common
8 Integer Representation
- Arbitrary numbers can be represented using binary
digits (0 and 1), a minus sign (-) and a
period(.)
- In the computer we only have binary digits
- If we are limited to nonnegative integers we can
represent values from 0 to 28-1 using 8 bits
- To represent negative integers we need some sort
of convention for the sign
- All conventions involve treating the most
significant (leftmost) bit in the word as a
sign-bit. (positive or negative)
- The remaining 7 bits are available for the
magnitude.
9Negative Integer Representation
- We will consider two different methods for
representing negative integers
- Sign magnitude
- 2s complement
- Each method has its advantages and disadvantages.
10Negative Integers - Sign Magnitude
- Simplest form of representation
- In an 8 word, the right most 7 bits hold the
magnitude of the integer
- Now an 8 bit word can represent values from
-28-1 to 28-1-1 (we need to use 1
allocation for zero)
- Example 6 in 8-bit representation is
00000110 -6 in 8-bit representation is
10000110
- Disadvantages
- arithmetic is difficult (addition does not
work!)
- two representations for zero
- 00000000
- 10000000
11Negative Integers - 2s Complement
- To perform the 2s complement operation on a
binary number, change all 1s to 0s and vice
versa then add 1
- Example 6 represented by 00000110 -6
represented by 11111010
- -4 represented by 11111100
- Advantages
- arithmetic is very straightforward (it works!)
- only one representation for zero (00000000)
122s Complement Addition
- Examples
- 00000001 1 11111110 -2 11111010
-6 11111100 -4 11111011 -5 11111010
-6
- Note that a carry beyond the end of the word is
ignored.
- 2s complement is the convention used on
computers today to represent negative integers.
13Floating Point Representation
- A range of very large and very small numbers can
be represented with only a few digits by using
scientific notation. For example
- 976,000,000,000,000 9.76 1014
- 0.0000000000000976 9.76 10-14
- This same approach can be used for binary
numbers. A number represented by MBE can be
stored in a binary word with three fields
- Mantissa
- Exponent E
- The base B is implicit (2) and need not be stored
14Typical 32-bit Floating Point Format
- First 8 bits contain the exponent
- The remaining 24 bits contain the mantissa
- The more bits we use for the exponent, the larger
the range of numbers available, but at the
expense of precision. We still only have a total
of 32 bits to represent the entire number
15Floating point representation
- How to represent the binary number
- 11010.11011011101
- This has to be converted to the form MBE
- . 1101011011011101 Mantissa
- The point has been moved 5 placed so exponent
5
- .110101101101110100000000 x 2 00000101
- Only the mantissa and the exponent need to be
stored to represent this number
- Note this assumes that all numbers are positive
16Range and Precision
- We already discussed the trade off between range
and precision with floating point numbers.
- The only way to increase both range and precision
is to use more bits.
- with 16 bits 216 numbers can be represented
- with 32 bits 232 numbers can be represented
- with 64 bits 264 numbers can be represented
- this applies to both integer and floating point
formats
- Most computers offer at least single precision
and double precision numbers.
17Character Representation
- Alphanumeric data such as names and addresses are
represented as strings of characters containing
letters, numbers and symbols.
- Each character has a unique code or sequence of
bits to represent it. As each character is
entered from a keyboard it must be converted into
its binary code. - Character code sets contain two types of
characters
- Printable (normal characters)
- Non-printable ie. characters used as control
codes. For example
- CTRL G (beep)
- CTRL Z (end of file)
18Coding Methods ASCII
- ASCII
- American Standard Code for Information
Interexchange
- strictly speaking a 7-bit code (128 characters)
- has an extended 8-bit version
- used on PCs and non-IBM mainframes
- widely used to transfer data from one computer to
another
- codes 0 to 31 are control codes
19ASCII Coding Examples
F1 463116 0100 0110 0011 00012
3415 3334313516 0011 001
1 0011 0100 0011 0001 0011 01012
Note that this is a text string and no arithmetic
may be done on it. A postcode is a good example
of the need to store numbers as text.
20Selection of Data Types
- Consider the type of data and its use.
- Alphanumeric for text (eg. surname, subject
name)
- Alphanumeric for numbers not used in calculations
(eg. phone number, postcode)
- One of the numeric data types for numbers
- Binary integers for whole numbers
- signed or unsigned as appropriate
- Floating point for large numbers, fractions, or
approximations in measurement
- Boolean for flags
- Date (if available) for dates
21Representing Graphics
- There are two ways of representing graphics
- Bit Mapped Graphics
- Vector Graphics
22Bit Mapped Graphics
- Any graphic is made up from a series of pixels
(Picture Elements).
- Each pixel is an individual point on the screen
23Bit Map
- Assuming only black and white (1 or 0) for each
pixel the image below would be stored as shown
0 0 1 1 1 1 0 0
0 1 0 0 0 0 1 0
0 1 0 0 0 0 1 0
1 0 1 0 0 1 0 1
0 1 0 0 0 0 1 0
0 1 0 1 1 0 1 0
0 0 1 0 0 1 0 0
0 0 0 1 1 0 0 0
Pixel Pattern using 8x8 grid
The BIT MAP of the image
24Resolution
- The quality of the image depends on the number of
pixels per inch (i.e. the density)
- More pixels means higher resolution and clearer
image
Pixel Pattern using 8x8 grid
Pixel Pattern using 16x16 grid
25Colour images
- As more colours are used then more memory is
needed to store each pixel and the overall image
- Using black and white only one bit is needed for
a pixel (1 for black 0 for white)
- Using 2 bits for each pixel allows
- 00 black
- 01 red
- 10 yellow
- 11 white ie 2 bits means four colours
26More Colour
-
- Bits per pixel No of colours
- 1 2
- 2 4
- 3 8
- 4 16
- 8 256
-
- n 2n
-
27Memory Storage
- The image below is 4 inches x 6 inches. The
resolution is 300 d.p.i. (dots per linear inch)
and the image supports 8 colours. Calculate the
memory requirements
Length 6x300 1800 pixels Breadth 4x300 12
00 pixels Total no pixels 1800x1200 21600
00 pixels (23 8) means 3 bits per pixel Stora
ge 3x2160000 6480000 bits 81000 bytes
792 KBytes
28Vector Graphics
- Each Image is made from objects
(line,rect,circle)
- Every object has ATTRIBUTES which define it
- To draw the rectangle below we need to know
Start X and Y coordinates
The length
The breadth
The thickness and colour of the lines
The type of line (dashed)
The fill colour
29A Vector Image
30Vector Vs Bit-Mapped
- Advantages of vector graphics (draw packages)
- Images can be enlarged without losing resolution
- Objects can be edited by changing their
attributes
- Objects can be layered on top/behind
- Images take up less disc space
- Ideal for drawing plans use library of objects
- Advantages Bit-Mapped (paint packages)
- Each pixel can be altered
- More realistic when used for photos/real life
31Images
- Bit-Mapped Vector graphic