Computer Science Students Guide
Computer Science Students Guide
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 the effects of changing elements of a bitmap image on the image quality and file size
Justify the use of a bitmap image or a vector graphic for a given task
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.
a number system based on the value 16 (uses the denary digits 0 to 9 and
Hexadecimal
the letters A to F).
ASCII code coding system for all the characters on a keyboard and control codes.
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.
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.
images that use 2D points to describe lines and curves and their properties
Vector graphics
that are grouped to form geometric shapes.
file compression method where the original file can be restored following
Lossless file compression
decompression.
This uses the digits 0 to 9 which are placed in ‘weighted’ columns. Example:
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.
128 64 32 16 8 4 2
2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹
Example: 1 1 1 0 1 1 1
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.
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
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
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
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
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
invert 1 0 1 1 1 0 1
the
+
digits:
add 1: 1 0 1 1 1 1 0
which
gives:
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.
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:
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:
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:
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
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.
B E 1
01 Information Representation 6
Skill Check 3
Solution
Using the above Table copy down the binary digits of each of these hexadecimal digits
B F 0 8
1011111100001000
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.
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
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.
$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
$0.3 0 0 1 1
+ +
$0.9 1 0 0 1
+ +
0.1 (carry) 0 0 0 1
1 1 0 1
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
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.
1.2 Multimedia
Images can be stored in two formats; Bit-map and vector graphics
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
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)
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.
file type
file size
image resolution
bit depth
type of compression
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
Thickness of line
Style of line
Line color
fill color
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
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
file formats are usually .svg, .cgm, .odg file formats are usually .jpeg, .bmp, .png
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.
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.
Using a higher sampling rate or larger resolution will result in a more faithful representation of the original sound source.
Pros Cons
01 Information Representation 14
Achieved by perceptual music shaping which:
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)
The first value represents the number of identical data items. The second value represents the code of the data item.
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.
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
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%.
Points To Note
The binary is a base 2 number system (0 or 1).
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
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.
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.
JPEG and MP3 are a type of lossy compression, where unnecessary data is permanently removed.
01 Information Representation 17