CScoursenotes
CScoursenotes
Alison Cowie
Portobello High School, Edinburgh
Contents
Data representation............................................................................................................................................3
Using binary to represent data.......................................................................................................................3
Integers..........................................................................................................................................................4
Real numbers.................................................................................................................................................5
Characters......................................................................................................................................................6
Vector graphics.............................................................................................................................................6
Bitmapped graphics.......................................................................................................................................6
Computer structure..........................................................................................................................................10
Computer architecture.................................................................................................................................10
Program instructions...................................................................................................................................12
Translator software......................................................................................................................................12
Environmental impact.....................................................................................................................................13
Security precautions........................................................................................................................................15
Firewalls......................................................................................................................................................15
Encryption...................................................................................................................................................15
2
Data representation
Binary means numbers are written in base 2 using the digits 0 and 1
Almost all data within computer systems is held in binary form. This is often referred to as digital data
2. It is easier to build electronic circuitry for carrying out calculations when only two values are
involved
3. The significant advances in hardware mean that it is possible to store and process enormous
quantities of digital information (information that is held in codes made up of 1s and 0s)
It depends largely on what the computer is expecting! Each piece of data will carry a code indicating
what type of data it is
3
Each type of data is stored in different ways
Integers
Storing only positive integers Range of values possible with n bits is 0 to 2n-1
e.g. What is 73 in binary? Put 1s and 0s in the right columns so that the numbers add up to 73
128 64 32 16 8 4 2 1
0 1 0 0 1 0 0 1
Put the 1s and 0s under the column headings and add up the numbers where there are 1s
128 64 32 16 8 4 2 1
1 0 0 1 1 1 0 0
4
Real numbers
A real number is a number that has a fractional part e.g. 67.341, -0.0005, -100.3
The number is stored using floating point representation using a mantissa and an exponent
The 6527802 is called the mantissa and the 4 is called the exponent
The mantissa and the exponent would be stored as separate numbers. The computer recreates the
number for calculations when it needs to
5
Characters
character – any symbol or letter found on a keyboard. Each character has a unique numerical value
inside the computer e.g. ‘A’ is 01000001 (=65)
character set of a computer – a list of all characters a computer can process and store. Different
computers have different character sets
control characters – do not print on the screen in the normal way. They control certain operations of
the computer such as ‘cursor up’, cursor down’, ‘clear screen’, ‘tab’, ‘return (enter)’, ‘delete’ etc.
(EXTENDED ) ASCII
American Standard Code for Information Interchange
An ASCII code is stored using one byte
28 = 256 therefore ASCII can represent 256 different characters
In ASCII, codes 0 to 31 are used for control characters e.g. 0001001 is the tab key
Aside: There are other coding systems for characters. For example, Unicode is designed to represent all
the characters from all of the world’s major languages. It was originally set up as a 16-bit code. 2 16 =
65536 different characters. Nowadays even more bits are used to give an even greater range of data
Vector graphics
Bitmapped graphics
6
Colour bitmapped graphics
- Several bits per pixel e.g. 10 bits per pixel means 1024 possible colours for each pixel
- True colour = 24 bits per pixel (the limit at which the human eye can distinguish between colour)
Resolution of a graphic
- determines the quality (accuracy) of the graphic
- the smaller the pixels, the higher the resolution and the better the quality
Storage requirements – file size remains constant regardless of the complexity of the image since the
whole screen is saved
Bit depth
If more than one bit is used for each pixel, then shades of grey or even colour can be represented. For
example, if two bits are used for each pixel then there are four possible combinations (00, 01, 10, 11)
which can be used to represent the colour of a pixel (e.g. white, light grey, dark grey, black). The greater
the number of bits used for each pixel, the greater the variety of colours)
Definition: Bit depth (colour depth) – the number of bits used to represent colour or shades of grey
in a graphic
A graphic has a bit depth of 6. How many colours does this allow? Ans: 26 = 64
7
Comparison of bit mapped and vector graphics
EDITING: When two shapes overlap in a bit mapped package such as Paint compared with a vector
graphics package, the shape on top will “rub out” the shape underneath
FILE SIZE: The file size of a bit mapped graphic stays the same regardless of the amount of detail in the
graphic because each pixel is stored regardless of its colour, whereas a vector graphic file size increases as
objects are added
The description of each object making up a vector graphic is called its “set of attributes”
RESOLUTION INDEPENDENCE: This is when the resolution of the graphic on the screen does not affect the
resolution of the printed graphic. This is a characteristic of vector graphics files because the processor
sends the file of object attributes that represent the graphic to the printer and the printer prints the
graphic off using its own resolution settings
When a bit map is printed out, the resolution of the printout is the same as the resolution of the bit map
on the screen regardless of the resolution of the printer. This is because the processor sends the bit map
as it is to the printer and it is printed as it is
To edit an object in a vector graphics file, the object needs to be selected and then the values of its
attributes (e.g. colour (attribute) red (value) to colour green
As bit depth and resolution increases, the quality of the image will increase but the file size will too,
meaning increased storage requirements and slower transmission times
Definition: True colour – where 24 bits per pixel are used to represent colours. This is considered to be
enough to fool the human eye that it is seeing ‘true’ colour and gives a total range of 16777216 colours
8
9
Computer structure
Computer architecture
Memory Processor
RAM
Data bus
R
ALU
e
g
Address bus i
s
t
e
r Control
s unit
ROM
e.g. if a program needs to add 2.73 and 5.76, these would be brought into the ALU where they
would be added together
e.g. if a program needs to compare the values of variables x and y, this would be done in the ALU
Control unit
Controls all the parts of the processor and makes sure that program instructions are executed in the
correct order
Makes sure that all events in the processor happen in the correct place and at the correct time
Registers
Registers are storage locations inside the processor chip that hold data while the processor is using it
MAR – Memory Address Register. This holds the address of the location in memory that is currently
being accessed
MDR – Memory Data Register. This holds the contents of the location currently being accessed
10
b) Memory
RAM - this is called volatile memory which means that it holds its data as long as the computer is
switched on, but when the computer is switched off any data in RAM is lost
ROM - this is called non-volatile memory which means that it holds its data permanently even when
the computer is switched off
N.B. Flash ROM can be reprogrammed whilst inside the computer and is now a very popular backing
storage e.g. USB flash drives and digital camera memory cards. It is replacing hard disk drives etc.
c) Buses
Data bus
Bi-directional. This bus transfers data between main memory and the processor
The number of wires making up the bus determines the quantity of data the bus can carry
and the greatest number it can carry is 28 – 1 (assuming just positive numbers)
Address bus
Uni-directional. The address bus indicates which address in memory is being read from or written to
The number of wires making up the bus determines the number of storage locations the processor
can access
e.g. if the bus has 32 wires then the number of possible addresses it can access is 2 32 and the range
of addresses is from 0 to 232 - 1
11
Program instructions
High level language instructions need to be translated into machine code instructions (in binary) in
order for the processor to be able to execute them. This means that, in the end, even the most
complicated programs like a computer game or an operating systems are just a huge collection of 1s
and 0s !
Portable software: A piece of software that can run on different computer systems i.e. it can be
translated into the machine code of a variety of processors e.g. for an Intel processor, for an AMD
processor etc.
Obviously, programming in binary machine code is time-consuming and hugely error-prone. Coding in
machine code is usually only done in situations where the programmer needs to refer directly to the
individual parts of the processor chip or refer directly to locations in main memory
Translator software
High-level languages are designed to be read by humans. They try to use simple, common language to
form instructions for the processor to carry out. For example, LiveCode
on placeFlags
repeat with flagNumber = 1 to 4
set the location of image id flagData[flagNumber]["imageID"] to flagData[flagNumber]["current position"] * 100, 200
end repeat
end placeFlags
Other examples of high level languages are C#, C++, Java, PHP, HTML, JavaScript, Perl, Ruby, Python,
Scratch
However, before these instructions can be executed by the processor, they must be translated into
low-level instructions. Each high-level instruction will translate into several low-level instructions
12
High-level language translators come in two forms:
Interpreters
The program (source code) is in memory along with the interpreter which translates and executes
each line of the program in turn
Advantage: Often used during development time. It is easier to locate errors since the interpreter can
highlight lines in the source code where the program fails
Disadvantages: The run (execution) is slower because of the simultaneous translation and because any
repeated line will be re-translated. In addition, the interpreter software takes up memory
Compilers
The program (source code) is translated into machine object code that can be executed by the
processor independently of the original source code. The only software that needs to be in main
memory to run the program is the object code
Advantages: The run (execution) will be fast because the translation has been done separately. In
addition, the original program source code is not available for people to view and possibly plagiarise.
Disadvantage: All errors need to have been corrected before source code can be compiled to run
independently
Environmental impact
A computing-related carbon footprint measures the amount of greenhouse gases emitted during the
production
use
disposal of computer equipment.
Using the Internet consumes energy at the user end but also involves electricity usage and therefore carbon
emissions by the companies that run the websites that users view
On the plus side, computers can help reduce carbon emissions by making equipment more efficient. An
example of this would be modern engine-management systems on cars that control the car engine to make
it more fuel efficient
Modern manufacturers of IT equipment are constantly looking for ways to reduce the energy consumption
of devices from low–power-consumption processors to low-energy-rated LED monitors
With modern advances in networking, employees can telecommute, which means that they can work from
home without having to physically commute by car, bus or train. Similarly, organisations can save money and
the environment by holding meetings using teleconferencing. Teleconferencing involves people meeting
together using webcams and microphones instead of having to leave their normal office and travel to
another city or country to meet with colleagues or customers.
Manufacture
Use
Disposal
What is WEEE?
WEEE is waste electronic and electrical equipment like TVs, fridges and computers. Many smaller items slip
through the net and are not treated or recycled and get buried in landfill sites. This wastes resources and
puts a major strain on the environment.
Stores that sell electrical equipment should provide facilities to take back WEEE. They must either offer in-
store take-back or be a part of a distributor take-back scheme (and so tell customers where to take it). There
should also be information in stores about the environmental impact of WEEE and what customers can do to
help reduce the impact their purchases make on the environment.
Consumers should consider the environmental consequences before replacing mobile phones, computers or
other gadgets. Could the equipment be upgraded or a refurbished product be bought instead?
Computer equipment can contain lead and other hazardous materials such as mercury and cadmium. Among
the risks when exposed to these materials are lead poisoning, high blood pressure, iron-poor blood, liver
disease, nerve and brain damage, and cancer. Because of the dangers involved with having these devices
lying around in public landfills, it is important to dispose of equipment responsibly. Toxic components leach
into the environment and this harms our ecosystem and, if recycling is done by low paid workers and/or in
developing countries, there are usually increased health risks and environmental impact
14
Solutions:
Recycle responsibly
Reuse – give unwanted computing devices to charities as soon as you stop using them
Reduce – think before purchasing a new device
Security precautions
Firewalls
A firewall is a program or piece of hardware that helps stop hackers, viruses and worms from entering a
computer over the internet. Some firewall software is free to download off the Internet e.g. ZoneAlarm
Encryption
Encryption is the encoding of data held on the system. This means that if the network is hacked into the
data are meaningless to the hacker because they do not have the security key to unlock or decipher the
encrypted data.
15