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
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.
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).
in Year 7, ASCII uses 5 bits to store each character and the binary value used to store it is based on the letters position in the alphabet.
So "HELLO" using ASCII is:
H E L L O
01000 00101 01100 01100 01111
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.
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.