Humans use a number system known as denary or decimal. This number system is made up of 10 numbers (0-9). It is thought that we use this system because when human beings learned to count, we used our fingers and thumbs and we have 10 of them in total.
In maths, we use place value to represent amounts of base 10 values, like so:
We then use these columns to represent values like 179 by putting the 1 in the hundreds column, the 7 in the tens column and the 9 in the ones column showing that we have:
100 | 10 | 1
1 7 9
(1 x 100) + (7 x 10) + (9 x 1) = 100 + 70 + 9 = 179
Computers don't have fingers, they use switches instead. Not unlike the switch for the lights, they can be either on or off, this means they have 2 states. To represent these two states we use a 0 or a 1.
In binary, we can also use place value, but instead of the columns increasing x10 each time, they increase x2. like so:
We then use these columns to represent values like 179 by putting 1's or 0's in the columns for the numbers that make 179, for example:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 0 1 1 0 0 1 1
(1 x 128) + (1 x 32) + (1 x 16) + (1 x 2) + (1 x 1) = 128 + 32 + 16 + 2 + 1 = 179
so 179 in Binary = 10110011
Hexadecimal is designed as a midway between human numbers (denary) and Computer numbers (binary) because humans are rubbish at remembering long sets of 0's and 1's.
Each value in a hexadecimal number represents 4 binary digits (0000 to 1111) meaning that the highest value that can be in any of its place value columns is 15, as such, hexadecimal is base 16 (0-15) the trouble is, we only have numbers from 0-9 so to get around this, we use the first 6 letters of the alphabet (A-F), like so:
Hexadecimal also uses place value like denary and binary do but instead of its columns increasing by x10 or x2, they are x16, like so:
We then use these columns to represent values like 179 by putting the amount of 16's or 1's in the columns needed to make 179, for example:
16 | 1
B 3
(B x 16) + (3 x 1) = (11 x 16) + (3 x 1) = 176 + 3 = 179
so 179 in Hexadecimal = B3
Hexadecimal numbers are expressed more compactly than binary numbers, and are much easier to understand and remember.
For this reason, hexadecimal numbers are often used instead of binary numbers and have several applications in computing.
One application you are probably familiar with is picking colours for graphics.
Hexadecimal numbers are also used in assembly language instructions such as ADD, 4F, 3A
There are two ways to turn a denary number into a binary number, the first uses the binary columns we showed you above here and the second requires dividing the number by 2 repeatedly until you have nothing divisible by 2.
The column method uses the binary colums and subtracts the columns value from the number you are converting starting from the biggest number.
For example:
number to convert = 234
binary columns:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
234 - 128 does go, so we put a 1 in the 128 column and move on to the 64 column with the remaining 106.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 |
106 - 64 also goes, so we put a 1 in the 64 column and move on to the 32 column with the remaining 42.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 |
42 - 32 also goes, so we put a 1 in the 32 column and move on to the 16 column with the remaining 10.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 |
10 - 16 doesn't go, so we put a 0 in the 16 column and move on to the 8 column with the remaining 10.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 0 |
10 - 8 does go, so we put a 1 in the 8 column and move on to the 4 column with the remaining 2.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 0 | 1 |
2 - 4 doesn't go, so we put a 0 in the 4 column and move on to the 2 column with the remaining 2.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 0 | 1 | 0 |
2 - 2 does go, so we put a 1 in the 2 column, at this point, the result is 0 so we put a 0 in the 1 column as we have nothing left to subtract.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 |
so our final conversion for 234 to binary is 11101010.
The division method divides the number by 2 and logs remainders as 1 or 0 and repeats this until there is nothing left that is divisible by 2.
For example:
number to convert = 234
234 / 2 = 117 remainder 0
117 / 2 = 58 remainder 1
58 / 2 = 29 remainder 0
29 / 2 = 14 remainder 1
14 / 2 = 7 remainder 0
7 / 2 = 3 remainder 1
3 / 2 = 1 remainder 1
1 / 2 = 0 remainder 1
We have now reached the end of the division as the value divided by 2 was equal to 0. to get the binary number we look at the remainders in bold above:
01010111 However, this isn't the correct answer, if we convert it back, we get 87. but we were converting 234, and the column method on the left shows the correct answer for 234 to binary.
So how do we fix it?
we read the remainder column from the bottom to the top:
11101010
so our final conversion for 234 to binary is 11101010. This is now correct.
______________________________________________________________________
One key thing to watch out for when using the division method is when the number is smaller than 128.
In this case, it only produces 7 remainders so you must add a 0 to the left of the result.
For example:
number to convert = 97
97 / 2 = 48 remainder 1
48 / 2 = 24 remainder 0
24 / 2 = 12 remainder 0
12 / 2 = 6 remainder 0
6 / 2 = 3 remainder 0
3 / 2 = 1 remainder 1
1 / 2 = 0 remainder 1
so 97 to binary is 1100001 but this is only 7 1's and 0's.
We need 8, so we add a 0 to the left of the result and write is as 01100001.
Converting binary to denary is simpler as it only has one method. We take the binary number and put it into the binary columns and then we add up the columns that have a 1 in them.
For example:
number to convert = 00100110
binary columns:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
place binary number in the columns
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 |
add up the columns with a 1
32 + 4 + 2 = 38.
so 00100110 in binary is 38 in denary.
When converting binary to hexadecimal, we split the binary number in half, from one 8-bit set of 1's and 0's to 2 4-bit sets.
For example:
01101110 would become 0110 1110
we then put these sets of 4 bits into the binary columns
8 | 4 | 2 | 1 | 8 | 4 | 2 | 1 |
0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
we then add up the columns with a 1 in them, just like the binary to denary conversion.
8 | 4 | 2 | 1 | 8 | 4 | 2 | 1 |
0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
4 + 2 = 6 8 + 4 + 2 = 14
so the first value is 6 and the second value is 14 but hexadecimal represents 14 using a letter.
Using the table above where we discuss hexadecimal, we can see that 14 is E so therefore:
8 | 4 | 2 | 1 | 8 | 4 | 2 | 1 |
0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
4 + 2 = 6 8 + 4 + 2 = E(14)
01101110 in hexadecimal is 6E
The hexadecimal to binary conversion is similar to the binary to hexadecimal one, but this time, we split the hexadecimal number in half, from one 2-bit set of values to 2 1-bit sets.
For example:
6E would become 6 E
we then write out our binary columns for 2 sets of 4 bits.
8 | 4 | 2 | 1 | 8 | 4 | 2 | 1 |
we then add a 1 to the columns that make the required value.
6 E(14)
8 | 4 | 2 | 1 | 8 | 4 | 2 | 1 |
0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
so 6 in binary is 0110 and E (14) is 1110.
6E in binary is 01101110.
When converting denary to hexadecimal, some people prefer to use binary as an inbetween, for example, converting the denary number into binary like we show you above and then converting the binary to hexadecimal also shown above.
However, there is a method for going from denary straight to hexadecimal. first, you divide the number you are converting by 16 and note any remainder, you then divide the remainder by 1 and that will produce the hexadecimal value.
For example:
number to convert = 168
168 / 16 = 10 remainder 8
8 / 1 = 8
so 168 in hexadecimal is 10 8, but hexadecimal represents 10 using a letter.
Using the table above where we discuss hexadecimal, we can see that 10 is A so therefore:
168 in hexadecimal is A8
In a scenario where there is no remainder, the second value is just 0.
For example:
number to convert = 172
172 / 16 = 11 remainder 0
0 / 1 = 0
so 172 in hexadecimal is 11 0, but hexadecimal represents 11 using a letter.
Using the table above where we discuss hexadecimal, we can see that 11 is B so therefore:
172 in hexadecimal is B0
Similarly to the denary to hexadecimal conversion, it is possible to convert to binary first. However, there is a way to do it without that and we will show you below.
this method is pretty much the reverse of the above method where instead of dividing the denary number by 16 you multiply the first value in the hexadecimal by 16 and then the second value by 1 and then add the results together.
For example:
number to convert = A8
Using the table above where we discuss hexadecimal, we can see that A is 10 so therefore:
10 x 16 = 160
8 x 1 = 8
160 + 8 = 168
so A8 in denary is 168
In a scenario where the second value is 0, you just apply the same rule.
For example:
number to convert = B0
Using the table above where we discuss hexadecimal, we can see that B is 11 so therefore:
11 x 16 = 172
0 x 1 = 0
172 + 0 = 172
so B0 in denary is 172.
Adding bianry numbers can seem daunting at first but as long as you remember the 5 simple rules, you can't get it wrong.
0 + 0 = 0
0 + 1 = 1 and 1 + 0 = 1
1 + 1 = 0 Carry 1
1 + 1 + 1 = 1 Carry 1
1 + 1 + 1 + 1 = 0 Carry 0, Carry 1
When adding binary numbers you stack one on top of the other and start from the right hand side following the rules above.
011010 + 111010
When adding binary numbers you stack one on top of the other and start from the right hand side following the rules above.
001010 + 111010 + 001110
To multiply and divide binary numbers we use shifts.
Shifting a binary number to the left multiplies it and shifting it to the right divides it. The number of places a number is shifted dictates how much it is multiplied or divided by.
To multiply a binary number we shift the binary number to the left in the binary columns. The amount we shift it by dictates the amount the number is multiplied by.
For example:
here is the binary number for 40, placed in the binary columns.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | = 40
to multiply this number, we must shift it left meaning that any 0's on the left will get cut off and empty spaces on the right get filled with 0's. Like this:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | = 80
We have shifted this number 1 place to the left and by doing so, the columns the 1's are now in are twice as big as their original columns so the answer is twice as big. 40 has become 80, therefore a left shift of 1 place has the arithmetic effect of multiplying by 2.
__________________________________________________________________________________________________________________________________________________
here is the binary number for 40, placed in the binary columns again.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | = 40
We are now going to shift it left by 2 places.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | = 160
We have shifted this number 2 places to the left and by doing so, the columns the 1's are now in are four times as big as their original columns so the answer is four times as big. 40 has become 160, therefore a left shift of 2 places has the arithmetic effect of multiplying by 4.
To divide a binary number we shift the binary number to the right in the binary columns. The amount we shift it by dictates the amount the number is divided by.
For example:
here is the binary number for 40, placed in the binary columns.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | = 40
to divide this number, we must shift it right meaning that any 0's on the right will get cut off and empty spaces on the left get filled with 0's. Like this:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | = 20
We have shifted this number 1 place to the right and by doing so, the columns the 1's are now in are half the size of their original columns so the answer is half the size. 40 has become 20, therefore a right shift of 1 place has the arithmetic effect of dividing by 2.
__________________________________________________________________________________________________________________________________________________
here is the binary number for 40, placed in the binary columns again.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | = 40
We are now going to shift it right by 2 places.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | = 10
We have shifted this number 2 places to the right and by doing so, the columns the 1's are now in are four times smaller than their original columns so the answer is four times smaller. 40 has become 10, therefore a right shift of 2 places has the arithmetic effect of dividing by 4.
To calculate the arithmetic effect of a binary shift, you need to do 2 to the power of the number of places you shifted it by.
For example:
here is the binary number for 40, placed in the binary columns.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
and here is the result of a right shift of 1 place:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
To calculate the arithmetic effect we do 2 to the power of 1, which equals 2, so the arithmetic effect of this right shift of 1 place is divide by 2.
Second example:
here is the binary number for 20, placed in the binary columns.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
and here is the result of a left shift of 3 places:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
To calculate the arithmetic effect we do 2 to the power of 3, which is 2 x 2 x 2 which equals 8, so the arithmetic effect of this left shift of 3 places is multiply by 8.
the smallest unit of storage you can have in a digital system like a computer is known as a bit. it is short for binary digit and is a single 0 or 1. They have the unit "b".
from bits, we get the other units which are made up of a number of bits:
nibbles = 4 bits.
Bytes = 8 bits. They have the unit "B"
Kilobytes = 1,000 Bytes / 8000 bits. They have the unit "KB".
Megabytes = 1,000 KB / 1,000,000 B / 8,000,000 b. They have the unit "MB".
Gigabytes = 1,000MB / 1,000,000 KB / 1,000,000,000 B / 8,000,000,000 b. They have the unit "GB".
Terabytes = 1,000 GB / 1,000,000 MB / 1,000,000,000 KB / 1,000,000,000,000 B / 8,000,000,000,000 b. They have the unit "TB".
Petabytes = 1,000 TB / 1,000,000 GB / 1,000,000,000 MB / 1,000,000,000,000 KB / 1,000,000,000,000,000 B / 8,000,000,000,000,000 b. They have the unit "PB".
A good way to remember the order they go in is with a mneumonic like:
big Bad Ken Might Go To Prison = bit Byte Kilobyte Megabyte Gigabyte Terabyte Petabyte
Every time we press a button on the keyboard, a binary signal is sent from the keyboard to the computer which then reads the signal, converts it to a letter and displays the letter you pressed or the command you entered on the screen.
This whole website has been built using a character set to make sense of the keys we have pressed on our keyboards.
The two types of character sets are ASCII and Unicode. We explore both below.
ASCII stands for American Standard Code for Information Interchange. As it's name suggests, ASCII stores the characters and buttons on an american keyboard and works with keyboards of other countries that use the same characters but maybe in different locations on the keyboard (like the UK).
ASCII uses 7 bits to store each character and the alphabet is stored twice, once in uppercase and once in lowercase. A is 65 and Z is 91 and a is 97 and z is 122. See the table below for more details.
As ASCII uses 7 bits to store each character, it can have a total of 127 characters as there are 127 unique binary numbers using 7 bits. The problem is, the 127 characters are all used which means that if we wanted to add any characters, we can't use ASCII.
This is where Extended ASCII comes in, it uses 8 bits per character, but by increasing by just 1 bit, it doubles the number of unique binary numbers to 256 meaning it can store 256 characters.
The problem with ASCII is that it only supportsthe English language and is already fully allocated (all 127 characters are assigned a value), that's where unicode comes in.
Unicode is a character set that uses 16 bits to store each character and because of that, it supports 65,536 characters, plenty for other languages like Chinese, Japanese and Arabic characters to name just a few.
ASCII is best for scenarios where you are transmitting the file, especially over a limited bandwidth connection and you know the person who is receiving it speaks or is using a computer in English.
Unicode is better for any scenario where the recipient may not speak English or if the file must contain characters that are not English.
Unicode is most commonly used now as most services and devices support emojis and these can only be stored in Unicode because ASCII is fully allocated.
Every image you see on a computer screen has to be stored as 1's and 0's. To do this, we use bitmap images.
Bitmap images are an image made up of a map of all the bits used to show the image, like a mosaic.
For example:
here, you can see an image of a sword and then how that image can be turned into a bitmap by dividing the image up into a grid of equal sized squares. these squares are known as pixels. Pixel is short for picture element and they are a single point in an image.
However, this still isn't in 1's and 0's for the computer to store it. To do this, we must assign a binary value to the colours used in the image, this gives us the number of bits used in each pixel and is known as the bit depth.
In this image, there are only 2 colours, black and white, so we are going to assign 0 to black (the absence of all lightwaves) and 1 to white (the presence of all lightwaves).
This then means the image can be stored and represented using binary. For example:
To calculate the file size of an image, we have to take 3 properties of the image and multiply them together, these properties are the height, width and bit depth.
Let's look at the image above:
the height of the image is 5 pixels.
the width of the image is 5 pixels.
the bit depth (number of bits in each pixel) is 1 bit.
Therefore, we do 5 x 5 x 1 = 25 bits
We can then divide this by 8 to get the number of Bytes this image takes up:
25 / 8 = 3.125 Bytes
The terms bit depth and colour depth are often used interchangably, however, there is a difference.
Bit depth refers to how many bits (1's and 0's) there are in each pixel.
Colour depth is the number of colours that can be shown in the image and this is dictated by the bit depth.
For example, if there are 3 bits in each pixel, you can have the following combinations:
000
001
010
011
100
101
110
111
There are 8 combinations and therefore, the colour depth is 8 but the bit depth is 3 because we can have 8 colours with 3 bits.
Increasing the bit depth or the colour depth increases the file size.
Earlier, we looked at an image that was 5 x 5 x 1 = 25 bits but if we increase the bit depth to 3 this now becomes 5 x 5 x 3 = 75 bits.
Similary, if we said the image needs to use 32 colours (32 colour depth) we would need 5 bits per pixel so it would become 5 x 5 x 5 = 125 bits.
Every sound we hear on a computer, tv show, film or mobile phone must be stored as 1's and 0's,
all sound starts as an analogue format, for example, the human voice is an analogue, continuous, soundwave. Therefore singing, talking, acting are all analogue sound. to turn this analogue sound into digital sound for the computer to store, we use a process called sampling.
When we sample, we measure the amplitude of the analogue soundwave at a given point in time. We then store this measurement and repeat until the whole soundwave is sampled.
the frequency that we take a sample (measurement) is known as the sample rate and is measured in hertz (1 hertz = 1 sample per second).
The number of binary bits used to store the sample is known as the sample resolution.
The final part is the duration that you are sampling for, for example, a full song is roughly 3 minutes (180 seconds) long.
To calculate the file size of a sound file, we have to take 3 properties of the sound and multiply them together, these properties are the sample rate, sample resolution and duration (in seconds).
Let's look at the soundwave below:
the sample rate is 3 samples per second.
the sample resolution is 4 bits per sample.
the duration (in seconds) is 8.
Therefore, we do 3 x 4 x 8 = 96 bits
We can then divide this by 8 to get the number of Bytes this sound file takes up:
96 / 8 = 12 Bytes
Data compression is where a file is subjected to a computer algorithm whose purpose is to make the size of the file smaller. There are many reasons why a file may be compressed but the most common 2 are:
To save space on the computer, the smaller the file, the more files you can fit on your storage.
To make transmission of the file faster, the smaller the file, the faster it is to send.
Lossy compression is when the algorithm used to compress the file does so by removing data. This type of compression reduces the file size by reducing the quality of the file and this cannot be restored when the file is decompressed.
Lossless compression is when the algorithm used to compress the file does so without removing any data. This type of compression reduces the file size without reducing the quality of the file as all data gets restored when the file is decompressed.
A lossless compression algorithm that works by using frequency and value pairs to shorten a "run".
example run: aaaaabbbbccddddddaaaaaaa
RLE version: 5a 4b 2c 6d 7a
What happened here was RLE (Run Length Encoding) has processed the run by finding the first value, in this case "a", and then found out how many "a" there are before the value changes, in this case, there are 5 a's before the value becomes "b". This is then repeated for "b" and so on until the end of the run is reached.
This compression is effective because we have gone from 24 values in the run to 10 values in the RLE version. It is lossless because if we decompress the RLE version we get back to the original run:
5a 4b 2c 6d 7a = aaaaabbbbccddddddaaaaaaa
RLE can also be used for bitmap images, for example:
The first line of this image can be compressed with RLE to become: 40 11, taking it from 5 values to 4 values.
Run Length Encoding is particularly effective with bitmap images as they typically have lots of repeating values, for example, an image with a blue sky will have many blue pixels next to eachother and they can all be compressed together.
A limitation of RLE though is that it isn't very effective with text, for example, the word "Hello" only has a repeating "l" so the space required actually grows:
1H 1e 2l 1o = 8 values whereas, "hello" is 5 values.
This shows that RLE is best used on files where there are many repeating valuse like bitmap images.
As we identified, Run Length Encoding isn't well suited to compressing text but with the number of messages and emails that are sent daily or the amount of homework you might do on Microsoft Word or PowerPoint, we need to be able to compress text.
This is where Huffman Encoding comes in.
Huffman encoding places text into a "huffman tree" with the most frequently occuring characters at the top and the least frequently occuring characters at the bottom.
Here is a huffman tree for the term "she sells sea shells"
Starting at the top of the tree, every movement left is a 0 and every movement right is a 1.
This allows us to have a huffman encoding for each letter:
E = 00
L = 01
S = 11
Space (Sp) = 101
A = 1000
H = 1001
This means that "she sells sea shells" can be represented as:
S H E Sp S E L L S Sp S E A Sp S H E L L S
11 1001 00 101 11 00 01 01 11 101 11 00 1000 101 11 1001 00 01 01 11
This encoding requires 49 bits to store "she sells sea shells"
in contrast, 7 bit ASCII would require 7 bits for each character so it would be 7 x 20 = 140 bits
ASCII = 140 bits
Huffman = 49 bits
140 - 49 = 91 bits
This is an effective compression as Huffman encoding has saved a total of 91 bits.