section 4: organisation & structure of data€¦ · web viewconvert decimal to binary to...

20
Section 4: Organisation & Structure of Data Homework Booklet WWW/EBI: MRI: Name:

Upload: others

Post on 05-May-2020

20 views

Category:

Documents


0 download

TRANSCRIPT

Section 4: Organisation & Structure of Data

Homework Booklet

WWW/EBI: MRI:

Name:

4.1 Binary, Decimal & HexadecimalComputers use binary - the digits 0 and 1 - to store data. A binary digit, or bit, is the smallest unit of data in computing. It is represented by a 0 or a 1. Binary numbers are made up of binary digits (bits), e.g. the binary number 1001.

The circuits in a computer's processor are made up of billions of transistors. A transistor is a tiny switch that is activated by the electronic signals it receives. The digits 1 and 0 used in binary reflect the on and off states of a transistor.

Computer programs are sets of instructions. Each instruction is translated into machine code - simple binary codes that activate the CPU. Programmers write computer code and this is converted by a translator into binary instructions that the processor can execute.

All software, music, documents, and any other information that is processed by a computer, is also stored using binary.

Convert binary to decimal

Binary numbers are usually represented by 8 bits - known as a byte.

Take the binary number 10101101. To convert this to decimal you need to construct a table like the one below.

Write 1 above the right-hand bit (known as the least significant bit because it is the smallest value) then double in value with each number moving from right to left. We double in value each time because binary is a base 2 number system. With decimal numbers that we are used to, we would times by 10 with each new column (thousands - hundreds - tens - units).

Remember that 0 represents 'off' and 1 represents 'on'. We can discard the values that are 0 and add up the remaining values which represent 1.

If we add up the values that represent 1 then it would be: 128 + 32 + 8 + 4 + 1

Decimal:

Base: 10

Units: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Example: 107

Binary:

Base: 2

Units: 0, 1

Example: 01101011

Hexadecimal

Base: 16Units: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, FExample: 6B

This would equal 173. Therefore, the binary number 10101101 = the decimal number 173.

Convert decimal to binary

To convert a decimal number into binary firstly construct a Base 2 table like below:

The general rule with converting from decimal to binary is:

Starting with the most-significant bit (left-hand side), compare the decimal number with the base 2 number.

If the decimal number (e.g. 75) is smaller, add a 0 and move along. If the decimal number (e.g. 75) is larger, add a 1 and take the base 2 number away from

the decimal number to give a new decimal number to compare. Then move along with this new number.

For an example, take the number 75. If we compare 75 and 128, the decimal number (75) is smaller than the base 2 number (128) so we add a 0 and move along:

If we compare 75 and 64, the decimal number (75) is larger than the base 2 number (64) so we add a 1 and take 64 away from 75 to give us a new number of 11:

11 is smaller than both 32 and 16 so we add 0's for the next two:

11 is larger than 8 however so we add a 1 and take 8 away from 11 to give us a new decimal number of 3:

Now that we have only 3 left you should be able to work out that 3 is smaller than 4 so we add a 1 then, because 3 is larger than 2 we add a 1 and our new number becomes 1. 1 is equal to 1 so we add a 1 leaving us with 0 and the conversion is complete:

Therefore the decimal number 75 = the binary number 01001011.

Convert binary to hexadecimal

First we must break up a binary value into groups of 4 (a nibble) each with binary values of 8 - 4 - 2 - 1.For example, 01011100 is split into 0101 and 1100:

Now we convert each nibble separately. This gives us (4 + 1) and (8 + 4) which is 5 and 12. 

BUT in hexadecimal, numbers from 10 to 15 are converted into letters: 

                          A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.

So 12 becomes C and our answer is that the binary value of 01011100 in hexadecimal is 5C.

Convert hexadecimal to binary

It is good practice to write out the hexadecimal conversion order for A (10) to F (15) in the margin of a test paper so that it is easier to work out. Remember: Hexadecimal converts any double digit number to a letter.

You must convert each separate value into a nibble. For example 9D will become 1001 for 9 and 1101 for D (13).

Then you can put the nibbles together for your answer: 9D in binary is 10011101.

Convert Hexadecimal to Decimal / Decimal to Hexadecimal

To convert hexadecimal to decimal or decimal to hexadecimal you must convert first to binary and then to either decimal or hexadecimal.

Quest ion Corner

Number Conversion:

1. Convert 01011010 to decimal.

2. Convert 11011110 to decimal.

3. Convert 23 from decimal to binary.

4. Convert 201 from decimal to binary.

5. Convert 0110 1111 to hexadecimal.

6. Convert 1101 0100 to hexadecimal.

7. Convert 34 from decimal to hexadecimal.

8. Convert E3 to binary.

9. Convert 9B to decimal.

4.2 Arithmetic Shift

Quest ion Corner

1. Shift 01011110 two places to the left. State the effect on the number (3)

…………………………………………………………………………………………………

…………………………………………………………………………………………………

………………………………………………………………………………………………….

2. Shift 11011101 four places to the right. State the effect on the number (3)

…………………………………………………………………………………………………

…………………………………………………………………………………………………

…………………………………………………………………………………………………

3. Explain what is meant by overflow (2)

…………………………………………………………………………………………………

…………………………………………………………………………………………………

Left Shift:Shifting binary values to the left will multiply them.

A shift of one place left multiplies by 2:

                            0001 1010     =   26

                            0011 0100     =    52

A shift of two places left multiples by 4:

                            0010 1100     =   44

                            1011 1000     =   176

If a value becomes too large and cannot be stored in the amount of bits available then there is an overflow error. 

Right Shift:Shifting binary values to the right will divide them.

A shift of one place right divides   by 2:

                            0001 1010     =   26

                            0000 1101     =    13

A shift of two places right divides by 4:

                            0010 1100     =   44

                            0000 1011     =   11When an odd number is divided, the answer is rounded down. 

                                    0101     =   5

………………………………………………………………………………………………….

4.3 Binary AdditionBinary values can be added together:

0 + 0 = 0

1 + 0 = 1

0 + 1 = 1

1 + 1 = 0 (remainder 1)

In decimal the sum below is 6 + 2 = 8. But you need to show your working out with the remainders.

If binary addition results in a number that is larger than can be represented in the number of available bits then an overflow error has occurred.

The result (20) is too large to store in only the 4 bits that are available in this example. Therefore an overflow error has occurred.

Quest ion Corner

Add together the following binary numbers, show your working.

1. 0101 and 0001 (3)

2. 0111 and 0101 (3)

0110 +00101000 1 1 1. 0 + 0 = 0

2. 1 + 1 = 10 (2 in binary) so we put 0 remainder 1 and carry it over to the next column.

3. With the remainder 1 from the 2 column, the 4 column becomes 1 + 1 so we put 0 again and another remainder 1.

4. The 8 column becomes 0 + 1 so it is 1

8   4   2   1

1110 + 01101 0100 1 1 1

3. 10110001 and 00110101 (3)

4.3 Representing ImagesThere are two types of images that can be stored on a computer system; raster and vector.

Raster Graphics

Raster graphics (sometimes called 'bitmap') are made up of pixels (minuscule dots that can be different colours).

Raster graphics are not scalable - enlarging them will create a blurry effect.

Raster graphics are generally larger than vector graphics because data is stored on each individual pixel.

Examples of raster images include photographs and screengrabs.

Vector Graphics

Vector graphics use objects (such as lines, curves and shapes) that are mathematically used to create an image.

Vector images are scalable - enlarging them will show no loss of quality.

Vector graphics are generally smaller than raster graphics.

Examples of vector graphics include logos and cartoons.

Calculating an image’s file size

File Size = Resolution x Colour Depth

The resolution of an image is the width in pixels multiplied by the height in pixels.

The colour depth (also known as bit depth) is the number of bits that are used to represent each pixel's colour. For example, 1 bit is used to represent two colours (black or white - 0 or 1). 2 bits will allow for 4 colours, 3 bits for 8 colours etc. A colour depth of 1 byte (8 bits) allows for 256 different colours. 

The RGB (Red, Green, Blue) colour model uses 3 bytes (a byte of 256 red shades, a byte of 256 green shades and a byte of 256 blue shades) that together can represent 16.7 million different colours.

Resolution = height x widthResolution =     8     x     8      = 64 bits--------------------------Colour Depth = 1 bit (only 2 colours)--------------------------File Size = Resolution x Colour DepthFile Size =        64       x           1         = 64 bits

File Size in bytes = 64 ÷ 8 = 8 bytes

Height – 8 bits

Width – 8 bits

Metadata

Metadata is additional data about an image that is stored with a file, such as: Colour depth, Resolution, Date created, Author, even if the flash was on.

Without metadata the computer might render the image incorrectly - e.g. it needs to know the width so it can shift the pixels to the next line.

An example of metadata in the mountain picture file (at the top of the page)

Quest ion Corner

Raster vs. Vector:

1. Describe three differences between raster and vector images (3)

………………………………………………………………………………………………………

………………………………………………………………………………………………………

……………………………………………………………………………………………………….

Image File Size:

2. A picture of a cat is 40 pixels wide by 50 pixels high. The colour depth is 8 bits (1 byte). What is the file size? Calculator permitted (2)

………………………………………………………………………………………………………

………………………………………………………………………………………………………

……………………………………………………………………………………………………….

Metadata:

3. Give three examples of possible metadata for an image (3)

………………………………………………………………………………………………………

………………………………………………………………………………………………………

……………………………………………………………………………………………………….

4.3 Representing SoundsSound on a computer must be converted from analog to digital waves.

To convert analog sounds into digital waves (i.e. using a microphone to speak into) the sound is sampled using an ADC (Analog to Digital Convertor) and stored as a binary value (such as 01010011) called a sample.

Digital sampling is discrete and not continuous like analog waves.

Therefore many samples are taken to recreate the analog wave as closely as possible.

Sample Rate

The number of samples taken per second is known as the sample rate.

Sample rate is measured in kilohertz (kHz) and CD quality is 44.1kHz (44,100 samples per second).

The image to the right shows CD quality compared to VOIP (a protocol usedfor online video such as Skype). The sample rate of a CD is much higher sothe audio quality will be better as it closer resembles an analog wave. However the higher sample rate, the larger the file size becomes as data is stored for each individual sample.

Generally, the higher the sample rate the more values are converted and the higher the overall quality of the sound.

Bit Depth

The bit depth is the number of bits available to represent each sample.

E.g. a sample with a bit depth of 4 could be 0101 or 0111 or 1010. A sample with a bit depth of 8 could be 01010110 or 1010110 or 11001111.

The image to the right shows four different waves, each with a varying bit depth. The higher the bit depth, the more bits are available to be used and thus the quality is often higher as the wave closer resembles an analog wave.

The file size will also be larger if the bit depth is higher, as each sample stores additional bits. A common bit depth is 16 bits.

Bit Rate

The bit rate is the number of bits that are processed per second. The bit rate is measured in kilobits per second (kps). Youtube has a common bitrate of 192kps and iTunes is 256kps.

Generally the higher the sample rate, bit depth and bit rate, the better the quality of the audio as there are more samples and more bits to represent each sample file size will be larger too.

Metadata

Metadata is additional data about sound that is stored with a file, such as:

The artist, album, genre, recording date or song title (think about different column titles on iTunes or Spotify). Features like sample rate, bit depth and bit rate also count as metadata.

Quest ion Corner

Representing Sounds:

1. Describe what is meant by sample rate (1)

………………………………………………………………………………………………………………………………………………………………………………………………………………

2. Explain the difference between bit depth and bit rate (4)

………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………

3. File A has a lower sample rate than File B. Suggest what the outcome of this might be on file size and audio quality and why (3)

………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………

Metadata:

4. Give three examples of possible metadata for a sound file (3).

………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………

4.4 CompressionTo compress a file means to make its size smaller.

Benefits of compression include:

Files take up less storage space (so more files can be stored). Files can be transferred quicker (because they are smaller). File can be read from or written to quicker.

There are two methods that are used to compress files: Lossless and Lossy.

Lossless Compression

When using lossless compression a file is compressed to a smaller size. When the file is decompressed there is no loss of data and it returns to its original condition. 

Original Image Compressed Image

Lossless compression is used for computer programs or word documents because if any data was to be removed the file would no longer make sense or even work properly. Because no data is removed, the file size when being transferred is larger than files using lossy compression so it is not used all of the time.

Lossy Compression

When using lossy compression a file is compressed to smaller size. When the file is decompressed some of the data is removed to decrease the file size. The decompressed Pikachu is an extreme representation; often you cannot see that any data has been removed.

Lossy compression is often used for images, audio video. Lossy compression is used to decrease file sizes, which is important on internet connections where data usage is limited, such as mobile phone networks.

Remember that lossy and lossless compression do not just refer to images.

Compression Ratio = Original File Size

Compressed File Size

Lossless Compression

Lossy Compression

20mb

4mb = 5:1

Example: A file has been compressed from 20 megabytes down to 4 megabytes. This is a

compression ratio of 5:1.

If a USB stick has 6 Mb of storage space left but a video is 35 Mb in size, suggest a suitable compression ratio.

Quest ion Corner

Compression:

1. Describe three benefits of compression (6)

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

…………………………………………………………………………………………………………….

……………………………………………………………………………………………………………

…………………………………………………………………………………………………………….

2. Explain the difference between lossless and lossy compression (2)

……………………………………………………………………………………………………………

…………………………………………………………………………………………………………….

3. Suggest what type of data could be compressed using lossless and what type of data could be compressed using lossy (2)

……………………………………………………………………………………………………………

……………………………………………………………………………………………………………

4. Give one advantage of using lossless over lossy and one advantage of using lossy over lossless (2)

……………………………………………………………………………………………………………

…………………………………………………………………………………………………………….

Compression Ratio:

1. A file has been compressed from 270 megabytes to 30 megabytes. Work out the compression ratio (3)

……………………………………………………………………………………………………………

…………………………………………………………………………………………………………….

2. Answer the question in the red box above (1)

…………………………………………………………………………………………………………….