Data Representation The storage of Text Numbers Graphics
As everything in binary is to do with powers of 2, we don’t use thousands, millions, billions etc. 1 bit (binary digit) = 0 or 1 (2 3 ) 8 bits = 1 byte (2 10 ) 1024 bytes = 1 Kilobyte (2 20 ) 1024 Kb = 1 Megabyte (2 30 ) 1024 Mb = 1 Gigabyte (2 40 ) 1024 Gb = 1 Terabyte
Data Representation ASCII is a 7 bit code giving a unique code for 128 characters. The first 32 are CONTROL CODES which make something happen. The rest are alphanumeric characters on the keyboard. As computers use 8 bits as a minimum, this allows an extended ASCII set to include symbols like square root, some foreign letters etc.
Data Representation Even with 8 bits for ASCII there are only 256 possibilities, not nearly enough to code alphabets from other languages UNICODE solves this problem. Unicode uses 16 bits for each character giving different codes. This proves sufficient to code all the main alphabets of the world.
Data Representation In base 2 binary, the headings are powers of two Headings:….8421 Number Giving 1 eight 1 four 1 two 0 unitsmaking 14 in decimal
To change any binary number to decimal (denary): Put the headings 2 n … above the number. Add up the headings where there is a one. Example: = 99 Data Representation
To change any decimal number to binary you divide repeatedly by 2. The remainders become the binary number. Example 57 2 | 57 2 | 28 R 1 2 | 14 R 0 2 | 7 R 0 2 | 3 R 1 2 | 1 R 1 0 R 1 Data Representation =
However, you can more easily work it out from the headings E.g. 46 This needs a 32 an 8 a 4 and a Data Representation
In two’s complement, you represent a negative by: Write its positive value in binary Flip each bit (1 0, 0 1) Add 1 Example: -18 using 8 bit numbers. 18 = Flip Add
How do you find the value of a two’s complement number? Flip and add 1 to get the value. (i.e. do the 2’s complement again) Eg This is -ve because it begins with a 1 Flip : Add 1 : = 53, so the original number was –53. Data Representation
In storing numbers the computer always sets aside the same amount of storage locations in RAM. It doesn’t matter if the number is 3 or 5 billion. Let’s say it just sets aside 1 byte for integers. 8 bits can hold 2 8 = 256 different values With 2 bytes for each integer: 16 bits can hold 2 16 = different values.
Data Representation Now if 8 bits can hold 2 8 = 256 different values The RANGE is 0 to 255 With 2 bytes for each integer: 16 bits can hold 2 16 = different values. The RANGE is 0 to
Usually 4 bytes are set aside for integer variables. For positive numbers this gives 2 32 different values. With a range from 0 to This is: 0 to Data Representation
For n bits there are : 2 n different values So the RANGE is 0 to 2 n - 1 Data Representation
For decimals Computers use The point floats to the FRONT of the number. Take This can be written.93 x 10 8 Why bother with the 10? Write it as.93 8 Why bother with the point? A computer stores it as 93 8
Data Representation The floating point number 93 8 Is made up of a MANTISSA: 93 And an EXPONENT: 8 Of course all this is done in binary on the computer with two’s complement for negatives.
With floating point storage locations have to be set aside for both the mantissa and the exponent. Decisions have to be made about how many bits for the mantissa and how many for the exponent. As you have seen this affects the range of values that can be stored. Data Representation
If you increase the storage for the mantissa you increase the PRECISION (accuracy) that real numbers can be stored in (more significant figures). If you increase the storage for the exponent, you increase the RANGE of numbers that can be stored. Data Representation
Computer pictures / images are made up of dots on paper, called pixels on a display. A typical printer will print 600 or 1200 dpi. A monitor displays 72 or 90 dpi. In black and white these pixels can be stored as a 1 or a 0. So one bit per pixel. Resolution is the number of pixels or dots used. Data Representation
To store colours, you need more than one bit per pixel. Colour depth is the name for how many bits are stored per pixel for colours. 1 bit gives 2 1 colours = 2 2 bits gives 2 2 colours = 4 3 bits gives 2 3 colours = 8 4 bits gives 2 4 colours = 16 8 bits gives 2 8 colours = bits gives 2 16 colours = bits gives 2 24 colours = (called true colour)
Data Representation If this was part of a screen using 4 colours 00white 01green 10red 11black Then it would be stored as shown on the left
Data Representation If a computer screen has 1024 pixels along and 768 up and had 256 colours You need 8 bits per pixel: 1024 x 768 x 8 = bits / 8 = bytes / 1024 = 768 Kb approx.
Data Representation If a graphic measuring 2” by 4” is scanned at 600 dpi using true colour, what is the storage requirement for the scan? True colour needs 24 bits per pixel 2 x 4 x 600 x 600 x 24 = bits / 8 = bytes / 1024 = Kb / 1024 = 8.25 Mb approx.
Data Representation Graphics that are stored pixel by pixel are called BITMAPS. Every pixel (and its colour) is mapped to a set of bits in memory or on backing storage. There is another type of graphic storage called VECTOR GRAPHICS.
Data Representation Vector Graphics store graphics as individual objects. Text is an object, a square, a circle, a line etc. Each object has ATTRIBUTES. For instance in a graphics package a rectangle might be object number 3. Attributes would be things like the co-ordinates of the corners, the line colour, fill colour etc.
Data Representation So a rectangle might be stored as : 3, 100, 200, 400, 800, 2, 3, 5 3 means rectangle. 100, 200 is the screen co-ordinates of the bottom left corner. 400, 800 the co-ordinates of the top right corner. 2 is the colour of the line 3 the line thickness 5 the fill colour.
Data Representation Bitmaps use a large amount of storage You can rub out parts of a bitmap You can use paint effects in bitmap. You cannot improve the resolution of a bitmap on a better device. Vector graphics only store the objects, not the whole screen. You can edit objects in vector graphics (resize, change colour etc) You can change layers (e.g. bring to front) Resolution independent (e.g. print better quality on a better printer) Differences between bitmap and vector graphics:
Data Compression Because bitmaps can have such large files we need data compression for storing or transmitting them. A 5 Megapix camera using true colour needs 15 Meg for each photo. Because of this data compression is needed, for instance jpeg could reduce that 15 Meg photo to 2 Meg without any noticeable loss of quality.