0% found this document useful (0 votes)
26 views17 pages

Computer Science Students Guide

Uploaded by

ahsantech33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views17 pages

Computer Science Students Guide

Uploaded by

ahsantech33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

01 Information Representation

Candidates should be able to:


Show an understanding of binary magnitudes and the difference between binary prefixes and decimal prefixes

Show understanding of the basis of different number systems

Perform binary addition and subtraction

Describe practical applications where Binary Coded Decimal (BCD) and Hexadecimal are used

Show understanding of and be able to represent character data in its internal binary form, depending on the character
set used

Show an understanding of how data for a bitmapped image are encoded

Perform calculations to estimate the file size for a bitmap image

Show an understanding of the effects of changing elements of a bitmap image on the image quality and file size

Show an understanding of how data for a vector graphic are encoded

Justify the use of a bitmap image or a vector graphic for a given task

Show an understanding of how sound is represented and encoded

Show an understanding of the impact of changing the sampling rate and resolution

Show understanding of the need for and examples of the use of compression

Show an understanding of lossy and lossless compression and justify the use of a method in a given situation

Show an understanding of how a text file, bitmap image, vector graphic, and sound file can be compressed

Definitions
Binary base two number system based on the values 0 and 1 only.

Denary base ten number system based on the digits 0 to 9

a number system based on the value 16 (uses the denary digits 0 to 9 and
Hexadecimal
the letters A to F).

Bit abbreviation for binary digit.

Byte unit of data that is 8 binary digits long

Nibble corresponds to 4-bits (half a byte)

each binary digit is reversed and 1 is added in the right-most position to


Two’s complement
produce another method of representing positive and negative numbers.

ASCII code coding system for all the characters on a keyboard and control codes.

Bit-map image system that uses pixels to make up an image.

Pixel smallest picture element that makes up an image.

number of bits used to represent the smallest unit in a sound or image file
Bit depth
– the larger the bit depth, the better the quality.

number of bits used to represent the colors in a pixel, for example, 8-bit
Color depth
color depth can represent 2^8 = 256 colors.

number of pixels that make up an image, for example, an image could


Image resolution
contain 4096 × 3192 pixels (12738656 pixels in total).

01 Information Representation 1
number of horizontal and vertical pixels that make up a screen display. If
the screen resolution is smaller than the image resolution, the whole image
Screen resolution
cannot be shown on the screen, or the original image will become lower
quality.

Pixel density number of pixels per square centimeter

images that use 2D points to describe lines and curves and their properties
Vector graphics
that are grouped to form geometric shapes.

number of bits used to represent sound amplitude (also known as bit


Sampling resolution
depth).

Sampling rate number of sound samples taken per second.

Bit rate number of bits required to store 1 second of sound

file compression method where parts of the original file cannot be


Lossy file compression recovered
during decompression, so some of the original detail is lost.

file compression method where the original file can be restored following
Lossless file compression
decompression.

a lossless file compression technique used to reduce text and photo


Run length encoding (RLE)
files in particular.

1.1 Data Representation


1.1.1 Number systems
Every one of us is used to the decimal or denary (base 10) number system.

This uses the digits 0 to 9 which are placed in ‘weighted’ columns. Example:

10000 1000 100 10 units

10⁴ 10³ 10² 10¹ 10⁰

Example: 3 1 4 2 1

Designers of computer systems adopted the binary (base 2) number system since this allows only two values, 0 and 1.

No matter how complex the system, the basic building block in all computers is the binary number system.

Each of the binary digits is known as a bit.

1.1.2 Binary number system


The binary system uses 1s and 0s only which gives these corresponding weightings. Example:

128 64 32 16 8 4 2

2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹

Example: 1 1 1 0 1 1 1

Converting from binary to denary:


Each value corresponding to ‘1s’ in the column is added to the total. For example, the binary number above is:
128 + 64 + 32 + 8 + 4 + 2 = 238 (denary)
The 0 values are simply ignored when calculating the total.
Converting from denary to binary:
There are two basic ways of doing this. Consider the conversion of the denary number, 107, into binary:
Method 1
This method involves placing 1s in the appropriate position so that the total equates to 107.

01 Information Representation 2
128 64 32 16 8 4 2

Example: 0 1 1 0 1 0 1

Method 2
This method involves successive division by 2; the remainder is then written from bottom to top to give the binary value.

Binary addition and subtraction


Up until now, we have assumed all binary numbers have positive values. There are several methods to represent both
positive and negative numbers. We will consider:
» one’s complement
» two’s complement.

In one’s complement, each digit in the binary number is inverted (in other words, 0 becomes 1, and 1 becomes 0). For
example, 0 1 0 1 1 0 1 0 (denary value 90) becomes 1 0 1 0 0 1 0 1 (denary value −90).

In two’s complement, each digit in the binary number is inverted, and a ‘1’ is added to the right-most bit. For example,
0 1 0 1 1 0 1 0 (denary value 90) becomes:

1 0 1 0 0 1 0 1

+ (since 1 + 1 = 0, a carry of 1) 1

1 0 1 0 0 = denary1 value −90 1 0

Two’s complement makes binary addition and subtraction more straightforward. The reader is left to investigate one’s
complement and the sign and magnitude method in binary arithmetic. Hence we primarily use the Two’s complement
method.
The two’s complement uses these weightings for an 8-bit number representation:

-128 64 32 16 8 4 2

Example 1 1 1 0 1 1 0 1

Example 2 0 0 1 0 0 1 1

The denary representation of the above numbers is as follows:


Example 1: −128 + 64 + 16 + 8 + 2 = −38
Example 2: 32 + 4 + 2 = 38

01 Information Representation 3
Skill Check 1
The binary of 104 is 0 1 1 0 1 0 0 0
Use Two’s complement method to find the binary value of -104.

Solution
invert 1 0 0 1 0 1 1
the
+
digits:
add 1: 1 0 0 1 1 0 0

which
gives:

Binary Addition

Example 1: Add 0 0 1 0 0 1 0 1 (37 denary) and 0 0 1 1 1 0 1 0 (58 denary)

0 0 1 0 since 37 0+ 58 = 95 1 0

+ 0 0 1 1 1 0 1

0 1 0 1 1
= 95 in denary 1 1

Example 2: Add 0 1 0 1 0 0 1 0 (82 in denary) and 0 1 0 0 0 1 0 1 (69 in denary)

0 1 0 1 since 82 0+ 69 = 151 0 1

+ 0 1 0 0 but 0 1 0

1 0 0 1
= -105 in1denary 1 1

This is due to the result of the addition producing a number outside the range of values which can be represented by
the 8 bits being used (in this case +127). This causes overflow.

Binary subtraction
To carry out subtraction in binary, we convert the number being subtracted into its negative equivalent using two’s
complement and then add the two numbers.

01 Information Representation 4
Skill Check 2
Carry out the subtraction 95 - 68 in binary

Solution
Convert the two digits into binary:

128 64 32 16 8 4 2 1

0 1 0 1 1 1 1 = 95 1

128 64 32 16 8 4 2 1

0 1 0 0 0 1 0 = 68 0

Find the Two’s Compliment of 68:

invert 1 0 1 1 1 0 1
the
+
digits:
add 1: 1 0 1 1 1 1 0

which
gives:

Add 95 and -68

0 1 0 1 1 1

+ 1 0 1 1 1 1

1 0 0 0 1 1 0

the additional ninth bit is simply ignored leaving the binary number 0 0 0 1 1 0 1 1 the denary equivalent of 27 which
is the correct result of the subtraction.

Measurement of the size of computer memories

Name of memory size Equivalent denary value (bytes)

1 kilobyte (1KB) 1 000

1 megabyte (1MB) 1 000 000

1 gigabyte (1GB) 1 000 000 000

1 terabyte (1TB) 1 000 000 000 000

1 petabyte (1PB) 1 000 000 000 000 000

Now since 1 byte wouldn’t allow you to store very much data memory sizes are measured in multiples and since they
are measured in power of 2, we use the binary system. Summarized in the table below:

Name of memory size Number of bytes Equivalent denary value (bytes)

1 kibibyte (1KiB) 2¹⁰ 1 024

1 mebibyte (1MiB) 2²⁰ 1 048 576

1 gibibyte (1GiB) 2³⁰ 1 073 741 824

1 tebibyte (1TiB) 2⁴⁰ 1 099 511 627 776

1 pebibyte (1PiB) 2⁵⁰ 1 125 899 906 842 624

01 Information Representation 5
1.1.3 Hexadecimal number system
The hexadecimal system is very closely related to the binary system.
Hexadecimal (sometimes referred to as simply hex) is a base 16 system with the weightings:

1 048 576 65 536 4096 256 16 1

16⁵ 16⁴ 16³ 16² 16¹ 16⁰

Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are used to represent
hexadecimal digits.
A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
Since 16 = 2⁴,
four binary digits are equivalent to each hexadecimal digit. The table below summarizes the link between binary,
hexadecimal, and denary:

Binary value Hexadecimal value Denary value

0000 0 0

0001 1 1

0010 2 2

0011 3 3

0100 4 4

0101 5 5

0110 6 6

0111 7 7

1000 8 8

1001 9 9

1010 A 10

1011 B 11

1100 C 12

1101 D 13

1110 E 14

1111 F 15

Converting from binary to hexadecimal and from hexadecimal to binary:

Starting from the right and moving left, split the binary number into groups of 4 bits.

If the last group has less than 4 bits, then simply fill in with 0s from the left.

Take each group of 4 bits and convert it into the equivalent hexadecimal digit using
the table above.

Convert 1 0 1 1 1 1 1 0 0 0 0 1 from binary to hexadecimal.

First, split it into groups of 4 bits:

1011 1110 0001

Then find the equivalent hexadecimal


digits:

B E 1

01 Information Representation 6
Skill Check 3

Convert this hexadecimal number to its binary equivalent.


BF08

Solution
Using the above Table copy down the binary digits of each of these hexadecimal digits

B F 0 8

1011 1111 0000 1000

Then put all the digits together:

1011111100001000

Use of the hexadecimal system:


Memory dumps:
It is much easier to work with:
B5A41AFC
then it is to work with:
10110101101001000001101011111100
So, hexadecimal is often used when developing new software or when trying to trace errors in programs. When the memory
contents are output to a printer or monitor, this is known as a
memory dump.

A program developer can look at each of the hexadecimal codes (as shown above) and determine where the error lies.

The value on the far left shows the memory location, so it is possible to find out exactly where in memory the fault
occurs.

Using hexadecimal is more manageable than binary. It is a powerful fault-tracing tool but requires considerable
knowledge of computer architecture to be able to interpret the results.

1.1.4 Binary-coded decimal (BCD) system


The binary-coded decimal (BCD) system uses a 4-bit code to represent each
denary digit:

0000=0 0101=5
0001=1 0110=6
0010=2 0111=7
0011=3 1000=8
0100=4 1001=9

01 Information Representation 7
Therefore, the denary number 3 1 6 5 would be 0 0 1 1 0 0 0 1 0 1 1 0 0 1 0 1 in BCD format.
The 4-bit code can be stored in the computer either as half a byte or two 4-bit codes stored together to form one byte. For
example, using 3 1 6 5 again …

Uses of BCD

BCD is used in the representation of digits on a calculator or clock display.

Each denary digit will have a BCD equivalent value which makes it easy to
convert from computer output to denary display.

It is nearly impossible to represent decimal values exactly in computer memories that use the binary number system.

Normally this doesn’t cause a major issue since the differences can be dealt with.

However, when it comes to accounting and representing monetary values in computers, exact values need to be
stored to prevent significant errors from accumulating.

Monetary values use a fixed-point notation, for example, $1.31, so one solution is to represent each denary digit as a
BCD value.

Consider adding $0.37 and $0.94 using fixed point decimals.

$0.37 0 0 0 0 . 0 0

+ +

$0.94 0 0 0 0 . 1 0

0 0 0 0 . 1 1

This gives us 1 1 0 0 (denary 12) and 1 0 1 1 (denary 11) which is incorrect as these nibbles don’t represent single denary
digits.
The solution to this is to add 0 1 1 0 (denary 6) at every point where the addition yields the nibble to have a value greater
than denary 9.
We can add $0.07 and $0.04

$0.07 0 1 1 1

+ +

$0.04 0 1 0 0

1 0 1 1

01 Information Representation 8
1 0 1 1 isn’t a denary digit hence we will add 0 1 1 0 (denary 6)

1 0 1 1

0 1 1 0

1 0 0 0 1

The fifth bit produced is carried to the next decimal position

$0.3 0 0 1 1

+ +

$0.9 1 0 0 1

+ +

0.1 (carry) 0 0 0 1

1 1 0 1

Again 1 1 0 1 isn’t a denary digit hence we will add 0 1 1 0

1 1 0 1

0 1 1 0

1 0 0 1 1

The fifth bit is again carried to the next position, adding 1 to 0 0 0 0 producing 0 0 0 1 giving us our final answer of:

= $1.31 0 0 0 1 . 0 0

1.1.5 ASCII codes and Unicode


The ASCII code system (American Standard Code for Information Interchange) is used in communication systems and
computer systems.

The standard ASCII code character set consists of 7-bit codes.

01 Information Representation 9
Unicode allows characters in a code form to represent all languages of the world, thus supporting many operating
systems, search engines, and internet browsers used globally.

It uses 16 or 32 bits to represent each character hence increasing the total number of characters that can be stored.

Requires more space as compared to ASCII.

1.2 Multimedia
Images can be stored in two formats; Bit-map and vector graphics

1.2.1 Bit-map images


Made up of pixels

The image is stored in a 2-D matrix of pixels.

the number of bits used to represent a pixel is called the color/bit depth.

Image resolution: number of pixels that make up an image; for example, an image could contain 4096 × 3192 pixels (12738
656 pixels in total).

Screen resolution: the number of horizontal pixels and the number of vertical pixels that make up a screen display (for

01 Information Representation 10
example, if the screen resolution is smaller than the image resolution then the whole image cannot be shown on the screen
or the original image will now be a lower quality

Picture taken by a digital camera; image resolution 4096 x 3192

Image rotated

To display the picture on a screen of 1920 x 1080, we would need to resize the picture (by lowering image resolution or
cropping it) or the picture could be rotated to fit the screen fully.

If the image resolution is lower than the screen resolution, although the image can now be displayed on the screen
without modifications, the image could become pixelated if zoomed in too much as pixel density is lesser

Pixilation refers to the pixel density (pixels per square inch) of the image

A is the original image, the more it is zoomed in, the fuzzier the picture becomes.

01 Information Representation 11
Calculating Pixel density:
Consider a phone screen of 5.5 inches, with a screen resolution of 1920 x 1080

1. add together squares of resolution size ((1920² + 1080²) = (3 686 400 + 16 640) = 4 852 800)

2. find the square root ( √4852800 = 2202.907 )

3. divide by screen size (2202.907 ÷ 5.5 = 401)

This gives us a pixel density of 401 pixels per square inch (PPI)

High-resolution images result in higher file size, decreasing the number of images that can be stored on a hard drive
and increasing the upload/download time of the image.

Calculating bit-map image file sizes:

Multiplying screen resolution with bit depth

Screen resolution 1920 × 1080 pixels and Bit depth of 24 bits


1920 × 1080 × 24 = 49766400 bits for the full-screen image.
Dividing by 8 gives us 6 220 800 bytes (1 byte is 8 bits)
File Header:
When saving a bit map image, a file header has to be included which contains:

file type

file size

image resolution

bit depth

type of compression

1.2.2 Vector graphics


Vector graphics are images that use 2D points to describe lines and curves and their properties that are grouped to form
geometric shapes. Vector graphics can be designed using computer-aided design (CAD) software.

Drawing List:
Vector graphic image contains a drawing list which is included in the file header, it contains:

command used for each object that makes up the graphic image

attributes that define the properties that make up each object

Thickness of line

Style of line

Line color

fill color

the relative position of each object

relative positions of objects to each other

When printing out vector graphics it is necessary to convert it into a bit-map image to match the format of most printers.
Comparison between vector graphics and bitmap images

Vector graphic images Bit-map images

made up of geometric shapes that require


made up of tiny pixels of different colors
definition/attributes

to alter/edit the design, it is necessary to change possible to alter/edit each of the pixels to change
each of the geometric shapes the design of the image

01 Information Representation 12
Vector graphic images Bit-map images

they do not require large file size since it is made because of the use of pixels (which give very
up of simple geometric shapes accurate designs), the file size is considerable

because the number of geometric shapes is


since images are built up pixel by pixel, the final
limited, vector graphics are not usually very
image is usually very realistic
realistic

file formats are usually .svg, .cgm, .odg file formats are usually .jpeg, .bmp, .png

Vector Graphic or Bit-map Image


Use the following to decide whether to use Vector Graphic or Bit-map.

Vector Graphics Bit-map Image

Can be resized Cannot be resized

Drawn to scale Is not drawn to scale

The image does not look real Image looks real

1.2.3 Sound files


Each sound wave has a frequency and wavelength; the amplitude specifies the loudness of the sound.

Analogue to Digital converter (ADC) is used to digitize sound.

Sound is filtered to remove high and low frequencies which are outside the human hearing range.

The sound waves are sampled at a given time rate to convert the analogue data to digital.

Approximate values are taken of the amplitude of the sound wave.

01 Information Representation 13
The x-axis shows the time intervals when the sound was sampled (0 to 20), and the y-axis shows the amplitude of the
sampled sound (the amplitudes above 10 and below 0 are filtered out in this example)

Sampling resolution (bit depth) : number of bits used to represent the sound amplitude. This impacts the accuracy of the
sampled sound.
Sampling rate: is the number of sound samples taken per second. This impacts the file size.

The amplitude of the sound wave is first determined at set time intervals.

This gives an approximate representation of the sound wave.

The sound wave is then encoded as a series of binary digits.

Using a higher sampling rate or larger resolution will result in a more faithful representation of the original sound source.

Pros Cons

larger dynamic range produces a larger file size

better sound quality takes longer to transmit/download sound files

less sound distortion requires greater processing power

Bit-rate: number of bits required to store 1 second of sound


bit rate = sampling resolution x sampling rate
file size = bit rate x length of sound

Features of sound editing software:

Edit start/stop times and duration of a sample.

Extract and save/delete part of a sample.

Alter the frequency and amplitude of a sample.

Fade in and fade out.

Mix and/or merge multiple soundtracks or sources.

Combine various sound sources and alter their properties.

Remove ‘noise’ to enhance one sound wave in a multiple of waves.

Convert between different audio formats.

1.3 File Compression


The two most common forms of file compression are lossless file compression and lossy file compression.
Lossy file compression: The file compression algorithm eliminates unnecessary data.
Lossless file compression: All the data from the original file can be reconstructed when the file is uncompressed again.
This is particularly important for files where the loss of any data would be disastrous (such as a spreadsheet file)

1.3.1 File compression applications


MPEG-3 (MP3): This lossy compression technology will reduce the size of a normal music file by about 90%. Music quality
can never match the ‘full’ version found on a CD, the quality is satisfactory for most purposes.

01 Information Representation 14
Achieved by perceptual music shaping which:

Removes frequencies that are outside the human hearing range

If two sounds are played at the same time, only the louder one can be heard by the ear, so the softer sound is
eliminated.

The quality of MP3 files can be different since it depends on the bit rate.
Photographic (bit-map) images: A common file format for images is JPEG, which uses lossy file compression. A JPEG will
reduce the raw bit-map image by a factor of between 5 and 15, depending on the quality of the original.

Vector graphics: Scalable vector graphics (.svg) are defined in XML text files which, allows them to be compressed.
Run-length encoding (RLE): A lossless file compression method used to compress several different file formats.

Reduces the size of a string of adjacent, identical data (such as repeated colors in an image)

A repeating string is encoded into two values.

The first value represents the number of identical data items. The second value represents the code of the data item.

RLE is only effective where there is a long run of repeated units/bits

Using RLE on text data

Each character requires 1 byte, hence the string “aaaaabbbbccddddd” needs 16 bytes. Since ASCII code is being used, then
the string can be coded as shown above.
Each number in the second row requires 1 byte of memory, the RLE code will need 8 bytes. This is half the original file size.
One issue occurs with a string such as ‘cdcdcdcdcd’, where compression is not very effective. To cope with this we use a
flag. A flag preceding data indicates that what follows is the number of repeating units.
Consider this example:

The original string contains 32 characters and would occupy 32 bytes of storage.
The coded version contains 18 values and would require 18 bytes of storage.

Introducing a flag (255 in this case) produces:


255 08 97 255 10 98 99 100 99 100 99 100 255 08 101

This has 15 values and would, therefore, require 15 bytes of storage. This is a reduction in file size of about 53%.
Using RLE with images

Black and white images

The figure below shows the letter F in a grid where each square requires 1 byte of storage. A white square has a value of 1
and a black square a value of 0.

01 Information Representation 15
The 8×8 grid would need 64 bytes; the compressed RLE format has 30 values,
and therefore needs only 30 bytes to store the image
Colored images
Figure 1.8 shows an object in four colors. Each color is made up of red, green, and blue (RGB) according to the code on the
right.

The original image (8 × 8 square) would need 3 bytes per square (to include
all three RGB values). Therefore, the uncompressed file for this image is 8 × 8 × 3 = 192 bytes.
The RLE code has 92 values, which means the compressed file will be 92 bytes in size. This gives a file reduction of about
52%.

General Methods of Compressing Files


For sound files:

Reduce sampling rate

Reduce sampling resolution

Points To Note
The binary is a base 2 number system (0 or 1).

Denary is a base 10 number system (0-9).

Hexadecimal is a base 16 number system (0-9 & A).

01 Information Representation 16
Converting from binary to denary, add the columns of numbers which have 1.

Converting from denary to binary, place 1 in the columns which add up to become the number.

Converting Hexadecimal to binary, write the equivalent 4 bits for each hexadecimal digit starting left to right.

Converting binary to hexadecimal, starting right to left split the binary value into groups of four and write down its
equivalent hexadecimal digit.

Two’s compliment is done by reversing all the binary digits and then adding one to the right-most bit resulting in the
negative equivalent of the original number.

Binary subtraction is done by converting the number being subtracted into its negative equivalent and then adding the 2
numbers.

Hexadecimal is used for memory dumps, Mac Addresses, and RGB colors in HTML

Hexadecimal is easier to debug and reduces errors as there are fewer digits to write

BCD uses a 4-bit code to represent each denary digit.

Overflow can be countered by adding 0 1 1 0 to the result.

Used in calculators, clocks, currency values

Unicode represents each character using 16 or 32 bits, hence can store alphabets of all languages.

If the screen resolution is less than the image resolution, then the screen can not display the full image and it has to be
cropped or rotated.

If the image is zoomed in too much it could become fuzzy.

Bit-map file size = screen resolution x bit depth.

The file header includes file type, file size, image resolution, bit depth, and type of compression.

Vector graphics also have a drawing list in the file header which contains a set of commands used to define a property.

ADC converts analogue sounds to digital signals which can be manipulated and edited.

Compression is used to increase transfer speed and save hardware space by reducing file size.

PNG is a lossless compression, that uses RLE

JPEG and MP3 are a type of lossy compression, where unnecessary data is permanently removed.

01 Information Representation 17

You might also like