Skip to content

Instantly share code, notes, and snippets.

@cinnamondev
Created May 2, 2022 12:52
Show Gist options
  • Save cinnamondev/92ef01402b7ead7e89e4e570d90f051a to your computer and use it in GitHub Desktop.
Save cinnamondev/92ef01402b7ead7e89e4e570d90f051a to your computer and use it in GitHub Desktop.
Eduqas (A-level) Computer Science WikiBooks Drafts & Additional resources. Focus on 2022 Advance Information.
https://www.youtube.com/channel/UCoHsD3Le9ppk4jgNyw51hLA
Channel going over WJEC A-Level Comp Sci (Welsh specific?)
https://www.youtube.com/watch?v=6bKeE1A5-LY&list=PL04uZ7242_M5PQnqp-pLNYF-lVR8gGy6u
MrBrownCS Component 1
https://www.youtube.com/watch?v=SbqXqQ-2ixs&list=PL04uZ7242_M6KzarBCtqtHAYyc7l6XDj3
MrBrownCS Component 2
https://en.wikibooks.org/wiki/A-level_Computing/WJEC_(Eduqas)
The (mostly incomplete) Wikibooks on WJEC (EDUQAS) A-Level computer science.

Table of Contents

Data Types

    For this course, you need to know about 5 different data types:

    - Boolean: Can be either true or false.
    - Character: Represents a single text symbol. (i.e: 'h')
    - String: Represents many characters. (i.e: "hello, world!")
    - Integer: A whole number. (i.e: 3)
    - Real: A number that can be expressed using decimal places. (i.e: 3.14)

Representing bits

Binary numbers (base 2)

In the construction of computers, we have developed our systems to use base 2 as on the lowest level, a computer is an electrical device that can turn signals either on or off.

Converting

To Denary

Convert <math>10100011_2</math> to Denary.

1. <math>10100011_2</math>

2.

128 64 32 16 8 4 2 1
1 0 1 0 0 0 1 1

4. 128 + 32 + 2 + 1

5. Result: 163

To Hex

The hexadecimal counting system's main usein computer science is to shorthand represent a binary number.

Hexadecimal value table
Hex Binary Denary
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
A 1010 10
B 1011 11
C 1100 12
D 1101 13
E 1110 14
F 1111 15

To convert binary to hex, simply look at the bits. Every 4 bits in a decimal value will represent a hexedecimal digit.

Convert <math>10100011_2</math> to hexadecimal.

1. <math>10100011_2</math> -> <math>1010_2</math> <math>0011_2</math>

2. <math>1010_2</math> = A16, <math>0011_2</math> = 316

2. Result: A316

Sign and magnitude

Binary can be used to represent a negative value too. One of the ways we can do this is with Sign and magnitude.

In sign and magnitude, the number remains the same, except for the most significant bit. The MSB is turned into a 'sign' bit.

The sign bit is used to say if its positive or negative, but you sacrifice some of your range. (The range of a sign and magnitude value is +127 to -127)

Example: Convert <math>01100011_2</math> to a negative binary number using sign and magnitude: Output: <math>11100011_2</math> (Just change the most significant bit)

Two's complement FIX THIS LATER

Converting a binary number to a negative version of itself is easy with two's complement. All you need to do is invert every bit in the sequence (so <math>00000111_2</math> (7) becomes <math>11111000_2</math>) and then add one (<math>11111000_2</math> becomes <math>11111001_2</math>).

Adding binary numbers

2 binary numbers can be easily added with a strategy similar to 'Short hand addition'.

<syntaxhighlight> 100101 + 010101 ----------- 1001010 ANSWER 11 1 1 CARRY BITS (ADDED TO RESULT) </syntaxhighlight>

Subtracting binary numbers

A binary number can be subtracted easily. However, it is easier to think of it as adding a negative number. When attempting to do this with sign and magnitude, you will realise however you cannot do this directly. This is one of the major downfalls of using sign and magnitude, and why more often Two's complement will be used, as it can be used to do this easily.

<syntaxhighlight> 11111001 (-7) + 00000011 ( 3) ----------- 11111100 (-4) ANSWER 1 CARRY BIT (ADDED TO RESULT) </syntaxhighlight>

Representing real numbers

Mantissa and Exponent
Sign and magnitude

A negative value in mantissa and exponent can be represented using sign and magnitude. The method is no different, you sacrifice the m.s.b (most significant bit) to represent the sign.

Two's complement

A negative value in mantissa and exponent can be constructed easily. The method is the same, one thing to consider is that decimal places are always positive

Hexadecimal numbers (base 16)

The hexadecimal counting system has 16 'digits'. We use hexadecimal as it can be used to easily represent binary shorthand, as the base of hex can be found using a power of 2 (2^4 = 16) This means one digit in hex, can be represented with a 4 bit value in binary. This makes converting between the two simple. Every 4 bits of a binary number can be matched to a digit in hex, and vice versa.

Hexadecimal value table
Hex Binary Denary
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
A 1010 10
B 1011 11
C 1100 12
D 1101 13
E 1110 14
F 1111 15

Converting hexadecimal to binary

You can find the denary equivalent by first converting each digit to binary, then converting the result to denary. Convert h'A3'

1. A= <math>1010_2</math> , 3= <math>0011_2</math>

2. <math>1010_2</math> <math>0011_2</math> = <math>10100011_2</math>

Converting hexadecimal to denary

You can find the denary equivalent by multiplying the digits like this:

(Denary equivalent value of digit) x 16^(digit place) Convert h'A3'

1. A = 10, 3 = 3

2. 10 x 16^1 + 3 x 16^0

3. 10x16 + 3x1

4. 160 + 3

5. Result: 163

You can find the denary equivalent by first converting each digit to binary, then converting the result to denary. Convert h'A3'

1. A= <math>1010_2</math> , 3= <math>0011_2</math>

2. <math>1010_2</math> <math>0011_2</math> = <math>10100011_2</math>

3.

128 64 32 16 8 4 2 1
1 0 1 0 0 0 1 1

4. 128 + 32 + 2 + 1

5. Result: 163

Storing characters

Table of Contents

Networking

Types

PAN

A PAN is a network that is extremely localised to your person. An example of a PAN is connecting bluetooth devices to a phone on your person. Bluetooth has an extremely short range in comparison to other transmission methods (i.e: Wi-Fi)

LAN

A LAN (Local Area Network) is a small area that is part of a small geographical area. Examples of LAN include anything from a home network, an office network or a university network.

There are significantly less clients on any one local area network, which makes them inherently more secure.

WAN

A WAN (Wide Area Network) is a larger network that uses a large geographical area. Examples of a WAN are the internet. A WAN is more insecure as there are a lot more clients on a WAN and thus you expose your device to potentially malicous actors.

Structures

Peer to peer

In a peer to peer network, each node in the network is directly connected to each-other. This makes the network easier to manage as devices can be disconnected from the network without stranding any one device. It also means that a single node can have a dedicated connection to another node which makes sending data over the network much simpler as it can be sent directly. However, peer to peer networks are also hard to manage, as each device has to keep track of every other device on a network.

Ring networking

NetworkTopology-Ring
NetworkTopology-Ring
A ring network is a network topology where each node is connected to 2 other nodes. This forms a network where there is a continous path between nodes for a signal to be transmitted to any node.

Ring networks avoid network collisions by only allowing data to travel in one direction and a token is required to send a signal on the network. Another way it can avoid colissions is by not allowing signals to traverse certain transmission lines until the signal currently being transmitted is clear of the line.

Ring networks are not neccesarily unidirectional, but for as far as the exam board is concerned, they are one direction.

Star network

Star Network
Star Network
A star network is the most common network topology, where each node in a network is connected to a central point (usually some sort of Wireless Access Point or Switch). This entirely avoids collisions as each node has it's own transmission line and does not need to share any transmission lines.

This greatly simplifies the additional processing required, and works well for larger networks and can have devices added and removed easily, but it also means the system is centralized, and if the central 'hub'/node were to fail, all the connections on the network would break. It also means additional cost as every node needs to be connected to the central hub.

Bus network =

A bus network topology is a network topology where each connection is connected to a signal connection line where all signals are transmitted to all devices. This is a very easy network to create, as every node or device can be connected as part of a single bus connection, and less cabling is required as they all share a single transmission line. This works well for small networks with low traffic, but it's mainly held back by network collisions.

colissions in a bus network will occur if 2 devices try to send data simultaneously. When this occurs, the data sent will be lost to the inteference caused by the colission (packet loss) in order to alleviate the issue of colission, a node on the network will be able to detect dropped packets by the "inteference" on the line caused by the colission, and it will wait a random amount of time before re-sending the data.

Another issue with a bus network is bandwidth is limited (as each device shares a line, they all also share the bandwidth). This limits the amount of data that can be sent by any one device on the network

TCP/IP

In networking, we have developed the 'layers' of processing required to transmit a signal correctly. These have been organised into 4 layers, which has their own unique role that has their own clear links between the layer above and/or below it. This greatly simplifies developing protocols as any one protocol does not need to implement the entire TCP/IP stack but instead one layer of it.

Layers:

1. Application layer

The application layer is the 'user-facing' layer of the stack. The protocols that implement this layer are what users would work with to send signals through the stack. Most protocols we need to be aware of are in this layer.

2. Transport layer

The transport layer is responsible for setting up how the 2 devices will communicate via agreed rules such as packet size and what transportation protocol to use.

3. Network Layer

The network layer is responsible for determing where the packet is to be sent and via what route. At this stage the relevant information about the source and host is added

(Destination, source address, etc...). This ensures if this packet needs to be elsewhere by another system it knows where to send the packets to continue.

4. Data links (also known as Network interface) The data link layer about the physical connections that are used for transmitting the data. For example, data can be transmitted via Ethernet or Wi-Fi.

Application layer

HTTP (S)

HTTP is one of the most commonly known protocols. It facilitates the sending and recieving of Hypertext (primarily) over the internet. This is primarily used for websites.

VoIP

VoIP allows for voice communication over a digital network. This is often a stand in between a telephone network or used as a replacement. It allows devices with sound and microphones to communicate via audio.

FTP

FTP facilitates the upload and download of files betwenc omputer systems via the internet. FTP is not neccesarily a secure protocol.

SMTP

Simple Mail Transfer Protocol. The POP3 protocol is used in conjunction to recieve emails, while SMTP is responsible for sending emails between e-mail servers.

IMAP
DHCP

DHCP is a standard protocol that is extremely common. On most networks, you don't want one device to perpetually own one IP forever, so it is important to use a protocol like DHCP to dynamically assign IP's to devices.

Transport layer

UDP

UDP (User datagram protocol) is a protocol where packets are sent to the device 'blindly'. This means the host does not check if the packets have actually been recieved or attempt any sort of error correction (i.e resending packets). UDP is more likely to drop packets and lose data, but in situations like video streaming where this is unlikely to cause an issue, UDP is more suitable as it does not have any additional overhead.

TCP

TCP (Transmission control protocol) is a protocol where packets are sent to the device with additional measures. It always ensures that a connection is established between it and the device it's connected to ensuring that data is always being sent to the correct destination. If packets are dropped, they are re-sent. This ensures data is not lost. This adds additional overhead which limits the maximum speeds data can be sent at with this protocol, but it also means data like text can be sent without losing data. This however is less suitable for applications like streaming as the additional overhead and the large bandwidth needed for video would likely result in buffering.

Network layer

IP - Each device on a network is assigned a unique identifier so that they can be identified easily. The Internet Protocol is responsible for adding this information about the IP Address of a device to a packet and what IP address it needs to go to so that data can be sent between 2 devices easily as data can be routed along the correct transmission lines to get to it's destination.

Data Link

The link layer describes the lowest-level architecture of the internet, such as the physical transmission lines and hardware that connect devices together. Every NIC has it's own unique MAC address (media access control address). A NIC is connected to host device to provide Networking to the host. This allows devices such as switches to be able to identify where to send oncoming traffic, which will contain information about the destination, with the switch having a table of the MAC addresses connected to it, so it knows where to send the data.

Table of Contents

Logic Gates

For any decision making and calculation done by the computer on the hardware level, logic gates are used. A logic gate takes a binary input, which can either be a 1 ('switched' on/true) or a 0 ('switched' off/false). The input is then processed to give an out a binary output.

AND

A diagram of an AND gate.
A diagram of an AND gate.
The AND logic gate requires both inputs to be 1 for the output to be 1 and is represented with a point ('.'), any other combinations produce an output of 0, this is demonstrated in the truth table below.

Format: A AND B, A+B

Input Output
A B A.B
0 0 0
0 1 0
1 0 0
1 1 1

OR

An OR gate.A and B are the inputs and Q is the output.
An OR gate.A and B are the inputs and Q is the output.
The OR logic gate requires only one input to be 1 for the output to be 1 and is represented with a plus symbol ('+'), any other combinations including a 1 will also produce an output of 1, see the truth table.

Format: A OR B, A+B

Input Output
A B A+B
0 0 0
0 1 1
1 0 1
1 1 1

NOT

A traditional diagram of a NOT gate.
A traditional diagram of a NOT gate.
The NOT (Negation) logic gate, sometimes referred to as an Inverter, flips any input that it receives. For example, if a 1 is input, a 0 will be output and vice versa. It is represented using a line above the input that is being inverted.

Format: NOT A, .

Input Output
A
0 1
1 0

XOR

A XOR gate, where only one input can be 1 for the output to be 1.
A XOR gate, where only one input can be 1 for the output to be 1.
The XOR (Exclusive OR) logic gate works exactly how it states in its name. Only one input can be a 1 and if any more are 1, or they are all 0, the gate will not return a 1. It is represented using a circle with a plus symbol within the circle.

Format: A XOR B, A ⊕ B.

You can also simplify boolean expressions to a single XOR gate (usually not required):

(A.) + (.B) = A ⊕ B

Input Output
A B A XOR B
0 0 0
0 1 1
1 0 1
1 1 0

NAND

A NAND gate.
A NAND gate.
The NAND (NOT-AND) gate simply flips the logic of an AND gate. Any combination of numbers that isn't a AND, will produce a 1 whereas an AND combination will produce a 0. This is represented as A.B with a line over the two.

Format: A NAND B,

Input Output
A B
0 0 1
0 1 1
1 0 1
1 1 0

NOR

A NOR gate.
A NOR gate.
The NOR (NOT-OR) gate flips the logic of an OR gate. The one combination which doesn't meet the OR gate logic is a 1, where both inputs are 0. This is represented as A+B with a line over the two.

Format: A NOR B,

Input Output
A B A NOR B
0 0 1
0 1 0
1 0 0
1 1 0

Simplification of Boolean Expressions

We can now apply the logic gate properties to taking and simplifying boolean expressions. A boolean identity is an expression that is always true no matter the application, nearly every Boolean simplification question will call upon this knowledge.

Simple boolean identities

The following are the most common boolean identities. A+0=A

A+1=1

A+A=A

A.=1

=A

A.1=A

A.A=A

A.=0

De Morgan's Law

De Morgan's law states:

= .

= +

De Morgan's law is very useful when simplifying boolean expressions.

Expansion

In order to simplify a boolean expression, you may need to first expand an expression before you can apply some of the identities.

(It is worth learning to do this as expressions like this and the way you simplify it is part of the simplification process for many of these questions. Take the following expression: A.(A+B)

At first, there doesn't seem to be many ways to simplify this, but if we expand the brackets, as logically it can be A and A OR B, so true results can be A.A or A.B

Now we have: A.A + A.B

We know A.A = A, but simplifying it we just get A+(A.B) and we can't go further from there, so we look at other identities. If A.A = 1, and we know A.1 = A, we can say A.A = A.1. Applying this yields:

A.1 + A.B

Now if we collapse this again to resemble the start...

A.(1+B)

Suddenly we can now see another identity we can use to simplify the expression (1+B = 1)

A.(1)

And another identity, A.1 = a

A

So we've managed to simplify A.(A+B) to A by first expanding the brackets.

Now try the following exercises:

Simplify the following boolean expression using boolean algebra, identities and De Morgan's law.

Application of Logical Operations

Masking

Masking is used to work out the state of a bit, which can either be a 0 or a 1. In the example below, the AND logical operator is used to determine the state of the 3rd most significant bit.

<math>10111011_2</math>AND

<math>00100000_2</math>Mask

<math>00100000_2</math>

Clearing

Clearing is used to reset the contents of a register to all 0s. This can be done using the AND logical operation or the XOR logical operation. You need to know both for the exam.

AND XOR
<math>10111011_2</math>AND <math>00000000_2</math>Mask <math>00000000_2</math>Cleared Register <math>10111011_2</math>XOR <math>10111011_2</math>Mask <math>00000000_2</math>Cleared Register

Encryption

Encryption converts data into ciphertext. This cannot be read unless the original key used to encrypt the data is known, the process of decryption. To encrypt and decrypt data, the XOR logical operator is used on the ciphertext.

Encryption Decryption
<math>10101010_2</math>XOR <math>11010001_2</math>Key <math>01111011_2</math>Ciphertext <math>01111011_2</math>XOR <math>11010001_2</math>Key <math>10101010_2</math>Original Data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment