A Level CS CH 1 9618
A Level CS CH 1 9618
Decimal Prefix:
Binary Prefix:
The maximum denary value one can store in a set number of binary digits, or alternatively, the range of
values that one can store in a set number of binary digits. Read carefully, these are not the same thing.
If I were to have 3 binary digits, the maximum value that I could store would be 1112, this equates to 4 +
2 + 1 = 710.
# 000
# 001
# 010
# 011
# 100
# 101
# 110
# 111
We could count these all out and write down: "There are 8 different values 3 binary digits can take". But
this isn't very clever, if one wants to find out the range and maximum values for 34 bits, one can't be
expected to write them all out. We are looking for a rule to save us the job and stop us making mistakes.
Rule: Max
Rule: Range
Number of values =
For an address bus with 6 wires, what is the highest address that can be given? How many addresses can
accessed?
One's complement: the binary number obtained by subtracting each digit in a binary number from
1(it means converting each 0 to 1 and each 1 to zero)
Two's complement: the one's complement of a binary number plus 1.
One of the advantages of using two’s complement representations is that it simplifies the process of
subtracting one number from another. The number being subtracted is converted to its two’s complement
form, which is then added to the other number.
Overflow: a condition when the result of a calculation is too large to fit into the number of bits
defined for storage.
ASCII
The 104-key PC US English QWERTY keyboard layout evolved from the standard typewriter keyboard,
with extra keys for computing.
ASCII normally uses 8 bits (1 byte) to store each character. However, the 8th bit is used as a check digit,
meaning that only 7 bits are available to store each character. This gives ASCII the ability to store a total
of
• Numbers
• Letters (capitals and lower case are separate)
• Punctuation (?/|\£$ etc.)
• non-printing commands (enter, escape, F1)
Take a look at your keyboard and see how many different keys you have. The number should be 104 for
a windows keyboard, or 101 for traditional keyboard. With the shift function valus (a, A; b, B etc.) and
recognising that some keys have repeated functionality (two shift keys, the num pad). We roughly have
128 functions that a keyboard can perform.
If you look carefully at the ASCII representation of each character you might notice some patterns. For
example:
As you can see, a = 97, b = 98, c = 99. This means that if we are told what value a character is we can
easily work out the value of subsequent or prior characters.
Without looking at the ASCII table above! If we are told that the ASCII value for the character '5' is 011
0101, what is the ASCII value for '8'.
We know that '8' is three characters after '5', as 5,6,7,8. This means that the ASCII value of '8' will be
three bigger than that for '5':
If you are worried about making mistakes with binary addition, you can deal with the decimal numbers
instead. Take the example where you are given the ASCII value of 'g', 110 0111, what is 'e'?
We know that 'e' is two characters before 'g', as e, f, g. This means that the ASCII value of 'e' will be two
smaller than that for 'g'.
64 32 16 8 4 2 1
1 1 0 0 1 1 1 = 10310 = ASCII value of 'g'
103 - 2 = 10110
64 32 16 8 4 2 1
1 1 0 0 1 0 1 = 10110 = ASCII value of 'e'
Exercise: ASCII
The ASCII code for the letter 'Z' is 90(base10), what is the letter 'X' stored as
How many ASCII 'characters' does the following piece of text use:
Unicode
The problem with ASCII is that it only allows you to represent a small number of characters (~128 or 256
for Extended ASCII). This might be OK if you are living in an English speaking country, but what happens
if you live in a country that uses a different character set? For example:
• Chinese characters 汉字
• Japanese characters 漢字
• Cyrillic Кири́ ллица
• Gujarati ગુજરાતી
• Urdu اردو
You can see that we quickly run into trouble as ASCII can't possibly store these hundreds of thousands of
extra characters in just 7 bits. What we use instead is unicode. There are several versions of unicode,
each with using a different number of bits to store data:
There are two methods to represent negative numbers (sign and magnitude method and two’s
complement form)
Uses of BCD
1. To display digital display such as screen of calculator and watch (BIOS of many personal computers
store time and date in BCD)
2. To represent fixed point decimal number such as currency $30.25
3. Hardware Algorithms (procedures) are east to implement on BCD codes.
Images
A digital image is a numeric representation (normally binary) of a two-dimensional image.
A large part of using modern computers involves sending pictures and films to each other, along with
using a graphical user interface. All of this involves computers saving and processing images. This section
will cover the two main image types: vector and bitmap, along with some compression techniques.
Bitmap Graphics - a collection of pixels from an image mapped to specific memory locations holding
their binary colour value.
Pixel - the smallest possible addressable area defined by a solid colour, represented as binary, in an
image.
Screen Resolution - the number of pixels per row by the number of pixels per column.
Using the diagram above we are going to work out how many pixels are required to display a single
frame on a VGA screen.
Height = 480
Width = 640
Area = Width * Height = Total Pixels
Area = 640 * 480 = 307200
Exercise:
Q: What is a Pixel?
A: The smallest possible addressable area defined by a solid colour, represented as binary, in an image.
A: The number of pixels per row by the number of pixels per column.
Q: If I have an image resolution of 700 pixels, and the height is 35, what is the width of the image?
A: 700 / 35 = 20 pixels.
A: Higher resolution images are able to display more detail, providing crisper images.
A: It will require a lot of space to store it. Meaning you'll quickly run out of memory, or it'll take a long
time to transmit images across the internet or other data route.
Colour depth - The number of bits used to represent the colour of a single pixel.
Bit depth - The number of bits used to represent each of the red, green and blue colours.
Exercise:
Q: For a colour depth of 8 bits, how many colours could each pixel store?
A:
Q: To represent 1024 colours per pixel, what colour depth would I need?
A:
Q: For an image of 30 by 40 pixels, what would the file sizes be for the following colour depths 4 bits?
A:
Q: When might one want to decrease the colour depth for an image?
A: When you want to save file space or when you only need a specific palate of colours such a mono-
chrome.
Vector Graphics: a graphic consisting of components defined by geometric formulae and associated
properties, such as line colour and style
Vector graphics are made up of objects and their properties. An object is a mathematical or
geometrically defined construct such as a rectangle, line or circle.
A bitmap file has to store the pixel data that defines the graphic, but the file must also have a file header
that contains information on how the graphic has been constructed. Because of this, the bitmap file size
is larger than the size of the graphic alone. At the very least the header will define the colour depth or bit
depth and the resolution.
File header: A set of bytes at the beginning of a bitmap file which identifies the file and contains
information about the coding used.
Exercise:
Q: You wish to create an image that will be made into a giant banner for the side of a building. What
type should you use and why?
A: Vector, as it allows for scaling without distortion and retaining its file size.
Q: You wish to create an image that will be used in a game, that will run on a mobile phone and a home
console. What type should you use and why?
A: Vector, as it allows for scaling without distortion and retaining its file size. You would only need one
image to use on all the different systems
Q: You want to take an image of a local cat stuck in a tree. What type should you use and why?
Sound waves in nature are continuous, this means they have an almost infinite amount of detail that
you could store for even the shortest sound. This makes them very difficult to record perfectly, as
computers can only store discrete/ digital data, data that has a limited number of data points.
The discrete approximations (in red) can be used to
Sound is a continuous set of data points recreate the original sound (grey). However, due to
formed by a wave. Computers sample this limitations in the number of samples we take we are
sound at discrete points to store a digital often unable to truly represent a sound wave, though
approximation we can get close enough for the human ear not to notice
the difference.
For a computer to store sound files we need to get the continuous analogue sound waves into discrete
binary values:
Analogue to Digital Converter (ADC) - Converts analogue sound into digital signals that can be stored on
a computer
Digital to Analogue Converter (DAC) - Converts digital signals stored on a computer into analogue sound
that can be played through devices such as speakers
Exercise:
A: Analogue data is continuous, allowing for an infinite number of possible values. Digital data is
discrete, allowing for a finite set of values.
Q: Name the device used by computers to convert sound files into sound coming out of the speaker
A: Analogue is continuous data, converting continuous data to discrete values may lose some of the
accuracy.
So we should know by now that sound waves are continuous and computers can only store discrete
data. How exactly does an Analogue to Digital Converter convert a continuous sound wave into discrete
digital data? To do this we need to look at how computers sample sound.
If you wanted to record a 30 second voice message on your mobile phone you would use the following:
Answer :
A sound wave is continuous data, whilst digital data is discrete and the representation is an
approximation of the original
Q: Why might you choose to have a lower sampling rate than a higher one for storing a song on your
computer?
Answer :
Q: The higher the sampling rate the more data is needed to be stored, meaning the larger the file size.
Answer :
the number of bits assigned to each sample, effecting the range of volumes that can be stored in a
sample
Answer :
Sampling Rate * Sampling Resolution
Answer :
16,000 * 8 * 10 = 1 280 000 Bits
Q: Work out the sample rate of the following sound file:
Sound Compression:
As you are probably aware an mp3 of the same length would be roughly 3Mb, a fifth of the size. So what
gives? It is easy to see that the raw file sizes for sounds are just too big to store and transmit easily, what
is needed it a way to compress them.
Lossless
Lossless compression - compression doesn't lose any accuracy and can be decompressed into an
identical copy of the original audio data
WAV files don't involve any compression at all and will be the size of files that you have calculated
already. There are lossless compressed file formats out there such as FLAC which compress the WAV file
into data generally 50% the original size. To do this it uses run length encoding, which looks for
repeated patterns in the sound file, and instead of recording each pattern separately, it stores
information on how many times the pattern occurs in a row. Let us take a hypothetical set of sample
points:
0000000000000000000001234543210000000000000000000123456787656789876
As you can see the silent area takes up a large part of the file, instead of recording these individually we
can set data to state how many silent samples there are in a row, massively reducing the file size:
(21-0)123454321(17-0)123456787656789876
Answer :
So that they take up less space and can be sent quickly across the internet or stored on portable music
players
Q: Name the two categories of compression available and give a file format for each
Answer :
Lossy (mp3/AAC/ogg) and lossless(FLAC)
012344444444444432222222222222211111111111111000000000000
Answer :
0123(11-4)3(13-2)(14-1)(11-0)
Answer :
perceptual coding reduces the quality of frequencies stored in a sound file that are beyond the auditory
resolution of most people
Answer :
• when you really care about the sound quality and you're not bothered about the file size
• when you are trying to make a sound file as small as possible