Higher Computing
Systems Unit
Higher Systems Data Representation
Topic 1
Data Representation
· Representation of positive numbers in binary including place values and range up to and including 32 bits
· Conversion from binary to decimal and vice versa
· Description of the representation of negative numbers using two’s complement using examples of up to 8 bit numbers
· Description of the relationship between the number of bits assigned to the mantissa/exponent and the range and precision of floating point numbers
· Conversion to and from bit, byte, Kilobyte, Megabyte, Gigabyte, Terabyte. (Kb, Mb, Gb, Tb)
· Description of Unicode and its advantages over ASCII
· Description of the bit map method of graphic representation using examples of colour/greyscale bit maps
· Description of the relationship of bit depth to the number of colours using examples up to and including 24 bit depth (true colour)
· Description of the vector graphics method of graphic representation
· Description of the relative advantages and disadvantages of bit mapped and vector graphics
· Description of the relationship between the bit depth and file size
· Explanation of the need for data compression using the storage of bit-map graphic files, as examples
Page -73-
Higher Systems Data Representation
Introduction
Computers are called two-state devices because all data is stored using two values. All the logic circuits used in digital computers are based upon two-state logic. That is, quantities can only take one of two values, typically 0 or 1. These quantities will be represented internally by voltages on lines, zero voltage representing 0 and the operating voltage of the device representing 1. The reason two-state logic is used is because it is easy and economic to produce such devices.
Measures:
o A bit is a Binary digit a 0 or a 1.
o 8 bits make a byte
o 1024 bytes in 1 Kilobyte (1024 = 210)
o 1024 Kbytes in 1 Megabyte (220)
o 1024 Mbytes in 1 Gigabyte (230)
o 1024 Gbytes in 1 Terabyte.
To go from bits to bytes, divide by 8.
To go from Kbytes to Mbytes, divide by 1024, etc.
Numbers
We use the base 10 number system to represent whole numbers, integers and fractional numbers. This number system uses the 10 digits 0 è 9 to represent numbers. The value of a decimal digit is given by its position within the base 10 number system.
Example:
10 000 1 000 100 10 1
34 043 is 3 4 0 4 3
3 x 10 000 + 4 x 1 000 + 4 x 10 + 3 x 1
The binary number system
When numbers are represented electronically, the most convenient base is 2, where each column, reading from the right is a power of two. The base 2 number system uses 2 symbols, 0 and 1 to represent a value.
Example 1:
16 8 4 2 1
10110 is 1 0 1 1 0
1 x 16 + 1 x 4 + 1 x 2 = 22
Example 2:
1101100110011010 is
32768 / 16384 / 8192 / 4096 / 2048 / 1024 / 512 / 256 / 128 / 64 / 32 / 16 / 8 / 4 / 2 / 11 / 1 / 0 / 1 / 1 / 0 / 0 / 1 / 1 / 0 / 0 / 1 / 1 / 0 / 1 / 0
= 32768 + 16384+4096+2048+256+128+16+8+2 = 55 726
So, to convert a binary number to our numbers (denary, or base 10), you put the headings starting from the right : …. 32 16 8 4 2 1 above the number and add up the headings where there is a 1.
The binary number system has the huge advantage that only two symbols are required, 0 and 1. These can easily be represented in a computer system by a switch or transistor being on or off, or by a high or low voltage level. Imagine how difficult it would be to represent 10 discrete logic values for the base 10 number system.
You can easily store data in binary e.g. magnetic discs using N/S magnetism or CDs using pits and lands to reflect light.
Binary representation also simplifies the number of arithmetic rules that need to be applied in calculations. Binary arithmetic has fewer rules. You need 100 rules for adding our numbers, you just need to know 0+0, 0+1, 1+0 and 1+1 (=10) to add binary numbers.
So the advantages of binary are:
¨ Simple arithmetic
¨ Simple electronic circuits
¨ Wide range of storage devices can use 2 values.
Another advantage is called ‘signal degradation’. If you used 0V for 0, 1V for 1 up to 9V for 9, voltages are never stable and if that 9V drops to 8.5 is it an 8 or a 9? With binary you can have a large difference between the values (e.g. 0V for 0 and 8V for 1)
Converting our numbers to binary:
There are two ways to convert decimal numbers into binary.
Method 1.
To convert 29 into binary: write down the binary headings (don’t go past 29), then work out which headings add up to 29:
16 8 4 2 1
To get 29 we need a 16, an 8 a 4 and a 1, so 29 =
1 1 1 0 1
Method 2.
This is guaranteed to work on any number and is useful for very large numbers. Here you continuously divide by 2, writing down the remainder each time until there is nothing left. The binary number is formed by reading the remainders up the way.
2 29
2 14 R 1
2 7 R 0
2 3 R 1
2 1 R 1 = 1 1 1 0 1
0 R 1
Something to know about storing numbers on a computer is that a fixed number of bits is always used. Let’s say a computer uses 32 bits to store numbers, then
3 would be stored as: 00000000000000000000000000000011
324 564 046 stored as: 00010011010110000111010001001110
The programming would be too difficult if variable length numbers were used, the computer wouldn’t know when a number ended! This means that there is a fixed range of values that can be used determined by how many bits you use.
The range of positive integers.
With 1 bit you can get 2 possible values: 0 or 1.
With 2 bits you can get 4 values: 00, 01, 10 and 11
With 3 bits you get 8 values: 000, 001, 010, 011, 100, 101, 110 and 111
1 bit 21 values = 2 range 0 à 1
2 bits 22 values = 4 range 0 à 3
3 bits 23 values = 8 range 0 à 7
… … …
8 bits 28 values = 256 range 0 à 255
… … …
n bits 2n values = 2n range 0 à 2n - 1
The range of positive numbers you can code is always one less because we start at 0.
For n bits the range is 0 to 2n - 1
You can add, subtract, multiply & divide in binary exactly the same as our numbers although you would find division difficult to get the hang of.
The only thing you need to remember is 1+ 1 = 10 (and 1+1+1 = 11). Also 10 – 1 = 1
Simple really!
So 1010 + 1011 = 1 0 1 0
+ 1 01 1 1
1 0 1 0 1
EXERCISE 1:
1. Convert these binary numbers to decimal:
a) 10101 b) 11001 c) 11100010 d) 10101010 e) 11110000
2. Convert these decimal numbers to binary:
a) 27 b) 37 c) 56 (use 8 bits) d) 97 (use 8 bits) e) 765 (use ÷ by 2 method)
3. Why are computers called two state devices?
4. Give two reasons why computers use binary.
5. What range of positive numbers can be stored using:
a) 1 byte b) 16 bits use powers of 2 for these answers: c) 20 bits d) 32 bits
6. Add these binary numbers:
a) 1 0 1 0 b) 1 1 0 1 1 1 c) 1 0 1 0 1 1 0 0
+ 1 1 +1 0 1 1 0 1 + 1 1 0 1 0 1 0 1
7. If you use a fixed number of bits to store numbers, what will happen if there is a carry at the end?
8. What number has been tattooed on this leg:
a) If you go ankle to knee?
b) If you go knee to ankle?
Negative numbers
An obvious way of getting computers to store –ves would be make the first bit a 1 for negative, 0 for positive. This is called sign and magnitude but unfortunately doesn’t work because adding gives the wrong answer and there is a +ve 0 and a –ve 0.
So two’s complement is used because there is only one 0 and arithmetic works correctly.
In actual fact the ALU in a processor can only carry out two operations:
· Binary addition
· Inverting (or flipping) bits à changing 1 to 0 and vice versa.
·
Two’s complement allows the ALU to store negatives and to subtract using these two operations. Subtraction is just adding the negative ( i.e. 7 – 2 = 7 + (-2) )
To store a –ve in two’s complement:
Step 1: Write down the positive value in binary
Step 2: Flip the bits ( 1 becomes 0 and 0 becomes 1)
Step 3: Add 1
For two’s complement to work correctly you must use a fixed number of bits for each number, so add 0s to the front to get the required amount.
Example 1: What is -17 in two’s complement using 8 bits
Step 1: 17 = 00010001
Step 2: flip: 11101110
Step 3: add 1: 11101111
So 11101111 is -17 in 8-bit two’s complement.
Example 2: What is -88 in 8-bit two’s complement?
Step 1: 88 = 01011000
Step 2: flip: 10100111
Step 3: add 1: 10101000
So 10101000 is -88 in two’s complement.
You must remember that positive numbers are still stored in ordinary binary. So you only need to do step 1 for +ve numbers.
Using two’s complement, -ve numbers will always start with a 1, +ves with a 0. Also two’s complement is its own inverse. So to convert back you flip and add 1.
So going from binary to our numbers:
Example 3: What is this two’s complement number? 10110001
We can see it is a –ve because it starts with 1.
So Flip : 01001110
Add 1: 01001111
Put the usual binary headings above this number and you get: 64 + 8 + 4 + 2 + 1 = 79
So the original number was –79
Example 4: What is the value of the two’s complement number11001111?
Flip: 00110000 Add 1: 00110001 work it out as 49, so answer -49.
N.B. If the number starts with a 0 it is positive, just put the headings above it to find out what it is.
EXERCISE 2:
1. Write these numbers in 8-bit two’s complement:
a) -34 b) -19 c) -97 d) -64 e) 28
2. These binary numbers are stored in 8-bit two’s complement, work out their value in denary.
a) 11000000 b) 10111111 c) 10011000 d) 01010001
3. Why do computers use two’s complement?
4. Work out these subtractions by i) subtracting them (remember 10 – 1 = 1 ) and ii) by adding the two’s complement.
a) 01001010 – 00000110 b) 01100111 – 00111111
(throw away the carry at the end when you add the two’s complement)
5. What range of values can be stored using 8 bits in two’s complement?
That covers how to store Integers. What about numbers outside of the range of integers? Also what about decimals?
For these numbers, computers use Floating Point. This is the same as Standard Form except the computer does not store the point or the base and counts the places from the BEGINNING OF THE NUMBER.
93 000 000 in Standard Form : 9.3 x 107
93 000 000 in Floating Point : 93 8
The 93 is called the MANTISSA
The 8 is called the EXPONENT.
Again, computers use a fixed number of bits to store floating point numbers. For instance with 32 bits they might use 24 bits for the mantissa and 8 bits for the exponent. Or they could use 20 bits mantissa, 12 bits exponent. This has an effect of the ACCURACY that numbers are stored in and the RANGE of values that can be stored.
With our numbers imagine we have a calculator that can only store 3 digits for the mantissa and 1 digit for the exponent:
E
93 000 000 would be stored:
12 875 000 would be stored:
Note the loss of accuracy.
The length of the mantissa determines how accurately (or precisely) floating point numbers can be stored.
2 340 000 000 cannot be stored at all. The point moves 10 places and this is out of our range. So the exponent determines the range of numbers that can be stored in floating point.
The more bits for the mantissa, the higher the accuracy
The more bits for the exponent, the bigger the range.
And vice versa.
TEXT
ASCII
American Standard Code for Information Interchange (ASCII) was first developed for teletypewriters and is now an internationally agreed standard for storing information.
ASCII uses 7 bits per character, giving a possible 128 different characters. It has 96 displayable characters, enough to represent every letter, number and punctuation mark of the English alphabet which forms its character set. Each character has its own unique code.
There are 32 special character codes known as control characters. They make something happen like new line, clear screen etc.
Now computers use bytes (groups of 8 bits), so the extra bit can be used either for error checking or extending the character set to include French, German etc characters like : ê, å, ñ, etc.
Now the problem with ASCII is it was designed for our Latin alphabet and as we have seen can be extended to cover Western European character sets, but what about Urdu, Arabic, Chinese and so on.
So ASCII is being superseded by Unicode. Unicode is a 16 bit code giving 65 536 characters which is enough to include all the world’s alphabets. ASCII forms the first 128 characters and extended ASCII forms the next 128 codes.
So Unicode has the advantage of including existing ASCII but extends to all character sets, so you can code every alphabet in the world (including ancient unused ones). The disadvantage is text takes up twice as much storage or twice as much bandwidth.
EXERCISE 3