Data Representation
Binary
An integer is a whole number which we represent using the decimal (base 10) number system. It is called this as there are 10 available characters (0-9) we use to represent any given number. e.g. 11, 34, 118.
A computer is a two-state device in that it uses electric charges set to two different values (ON or OFF) to store data and program instructions. Due to this, the computer stores these numbers using binary. Binary numbers only use the digits 1 and 0.
For National 5, you need to be able to convert whole numbers from denary (‘normal’ numbers with 10 digits, what we use) to binary. You also need to convert binary numbers back to denary.
Binary - what the computer uses (10011101)
Denary - what we use (= 157)
The binary numbers you work with use eight place values/columns, starting (right) at 1, and doubling each time:
Binary to Denary
The binary number 0001 0110 can be represented as a denary number by using the following method:
Write the binary number under the column headings and add together any columns that have a 1 stored in them.
This gives you the answer:
16 + 4 + 2 = 22
Denary to Binary
The denary number 30 can be represented as an 8-bit binary number by using the following method:
Add a 1 to any columns, that when added together, make up the decimal number.
Add a 0 to the other columns.
16 + 8 + 4 + 2 = 30
Which leaves us with the 8-bit binary number: 0001 1110
Range of values represented using 8 bits
If using 8-bits to represent a binary value, the lowest number that can be represented is 0, and the highest is 255.
If all the values are off, the number is 0:
If all of the values are on, the number is 255:
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
Floating Point Representation
A floating point number is one with a decimal point.
0.5571257
Inside the computer, floating point numbers are stored with a mantissa and an exponent.
If you are asked how floating point numbers are stored, you would say that it is with a mantissa and an exponent.
The floating point number is stored in something that looks a bit like scientific notation.
In this example, the mantissa is 58125 and the exponent is 4.
We remove the decimal point when writing the mantissa.
We remove the ‘10’ when writing the exponent.
The mantissa dictates the precision of a number, the more bits allocated to the mantissa, the more precise a number can be
If you want to be store a large range of numbers then you need to allocate more bits to the storage of the exponent, as the exponent dictates the range of numbers that can be represented
Representing Text
Printable and control characters are represented by using extended ASCII, which is an 8-bit code used to store up to 256 (28) different characters.
ASCII is limited because it can only store Roman / Latin alphabet letters from A-Z, a-z.
ASCII cannot store characters from other alphabets such as Greek, Arabic, Chinese etc.
An ASCII table shows all of the 256 characters and a number associated to each character.
Types of Character
Extended ASCII is made up of printable characters and control characters.
Printable characters are the letters, numbers and symbols that you see on the screen.
Control characters are signals that do not appear as printed symbols in the text (messages like “escape” and “delete”).
Printable Characters
A z #
4 ? Y
Control Characters
Escape
Delete
Function Keys
Calculating Space
Because extended ASCII uses 8 bits for each character, we can calculate how much space is needed to store a particular message:
Space needed (in bits) = Length of the message x 8
How much space would be need to store the following phrase?
No, I am your father!
21 characters x 8 bits per character
= 168 bits
Graphics
Bitmaps
A bitmap is a grid of pixels. Each pixel has a colour associated with it.
Bitmaps can be black and white, or have lots of colours. The important point is that it is made up of a grid of individual squares called pixels.
The number of pixels used in a bitmap is called the resolution; the higher the resolution, the better the quality and the larger the file size.
Bitmap graphics are resolution dependent. This means when they are created they have a set number of pixels; if the graphic is scaled up or down it may become pixelated and lose quality.
Example
This image has:
4 x 4 resolution = 16 pixels
bit depth of 8 bits per pixel
= 28
= 256 different colours
Vectors
A vector graphic isn’t stored as pixels.
In a vector, the image is made up of shapes called objects. Each object has a list of attributes.
You need to know about four types of objects. Each type of object has attributes:
Fill colour = the colour the object is ‘filled in’ with
Line colour = the colour of the line/border around the object, if there is one
X and Y coordinates = the position of the object in the graphic
Bitmap vs Vector
Vector graphics generally use less storage space than bitmaps, unless it contains lots of layers and lots of complex objects.
They are resolution independent which means they can be resized without any loss of quality; unlike bitmaps which can look blotchy or pixelated when resized.
Vector graphics are better suited for simple graphics that involve shapes, rather than detailed photo graphics.