Data representation
#learning #knowit
Encoding the world in base2
Why Base2?
First, computers were built using electromechanical relays.
Then vacuum tube valves.
Then the semi-conductor transistor (around late 1950's)
And now we can put billions of transistors together in a little postage stamp sized silicon chip. These switches...transistors...are 14nm large (14 millionth of a meter)
In fact, transistors are so small that they physically cannot get any smaller which is why microprocessor manufactures had to start adding more cores (CPU's) to their new chips in order get more speed.
But they are still just switches!
So how can switches make a computer?
Problem: How to represent all types of data...
...using just 1's and 0's?
How does a computer actually work?
A digital computer is not magic, it is built using “switches“. Lots of them.
A “computer” was a person that solved calculations all day and wrote the answers down into a book that was then sold to engineers, scientists…anyone who needed to know the answer to hard sums without a calculator (because they hadn’t been invented yet)
Alan Turing wanted the computer to be called the “Universal Machine” but as it was the computer who lost their job when it was eventually created so the machine inherited the name.
So a computer is, amongst other things, a machine capable of calculations. OK how do we create this?
First, we need to be able to store numbers bigger than 1!
Mathematicians took the switch and put them together to form….x8 switches! They called them “a byte” (BTW x4 switches are called a “nibble” – not joking).
Starting from the right, each switch was given a value, that doubled. Like this:
Now we can store numbers from 0 to 255. How? Switch on the switches to add up to the value you want to store. For example:
Binary game
Try your binary conversion skills - CLICK HERE.
You can even download it to your phone so you can play at all times.
If you put some of these logic gates (AND and XOR) together in a certain way you can create the “1-bit half adder“:
Try it for yourself
Why not try and create this circuit yourself using this logic gate simulator - CLICK HERE.
If you look at the truth table for this logic circuit you can see that it adds up two 1-bit numbers:
Magic? No Logic!
Here is how you make an AND and OR gate using switches:
So a switch can now store numbers and add them up.
Once you can add, you can multiply (for example 3 x 3 is the same as 3 + 3 + 3).
Then the sky is the limit!
Representing units
Candidates should be able to:
define the terms bit, nibble, byte, kilobyte, megabyte, gigabyte, terabyte
understand that data needs to be converted into a binary format to be processed by a computer.
As explained above, everything....EVERYTHING...needs to be converted to 1's and 0's (on/off) to be able to be stored and processed by a BINARY computer.
1 bit = Binary digIT = 1 or 0 => for example stores True or False, On or Off
4 bits = 1 nibble => for example stores half a machine code instruction (an op-code or operand)
8 bits = 1 byte => for example stores x1 character encoded using ASCII
1000 bytes = 1 kilo byte => 1KB = for example stores x1000 characters (a page of A4)
1000 KB = 1 mega byte => 1MB = for example stores an average MP3 file
1000 MB = 1 giga byte => 1GB = for example about x1 hour of movie streaming from Netflix or iPlayer etc.
1000 GB = 1 tera byte => 1TB = for example about 2 million digital photos
(N.B. 1Kb (little 'b') means Kilo BITS, 1KB (upper 'B') means Kilo BYTES)
Representing numbers
Candidates should be able to:
convert positive denary whole numbers (0-255) into 8-bit binary numbers and vice versa
add two 8-bit binary integers and explain overflow errors which may occur
convert positive denary whole numbers (0-255) into 2-digit hexadecimal numbers and vice versa
convert between binary and hexadecimal equivalents of the same number
explain the use of hexadecimal numbers to represent binary numbers.

Converting between base 10 (decimal) and base 2 (binary)

Converting between base 10 (decimal) and base 16 (hexadecimal)

Converting between base 16 (hexadecimal) and base 2 (binary)
Why use Hexadecimal?
A good question. Hex is used purely to represent binary in a more human digestible format.
In RAM numbers are stored as binary. If you wanted to read these values then you would be reading lots of 1's and 0's. This would be very difficult to comprehend with our brains.
By representing (not converting to) the binary as hex, our brains can comprehend the values without going crazy. That's it.
For example, let's say you are a digital artist and want to tell someone about a particular blue: Powder Blue.
Colours can be represented in terms of how much red, green and blue content they have. This is stored as a number - a binary number.
So, do you call your friend and say:
"Hi, I've found the perfect colour: 1011000011100000011100110"
Because your friend would probably make a mistake in writing down the digits and certainly wouldn't understand what it was.
No, you would probably say:
"Hi, I've found the perfect colour: #b0e0e6"
Your friend would definitely be able to write this number down accurately and probably, with experience, understand roughly what sort of colour this was.
Hex is used purely to represent binary in a more human digestible format.

Binary addition
In the exam it will be required to show working out including showing the carry bit and possibly the overflow bit.
CLICK HERE for more information on the ALU.
Representing characters
Candidates should be able to:
explain the use of binary codes to represent characters
explain the term character set
describe with examples (for example ASCII and Unicode) the relationship between the number of bits per character in a character set and the number of characters which can be represented.
A character set: "The characters/symbols a computer uses/understands/displays"
ASCII - American Standard Code for Information Interchange
A 7 bit number character set (+1 bit used as a check digit) that represents up to 128 different characters - CLICK HERE
Great if you are American and speak English. But not good if you speak Arabic or Mandarin as these languages and 10,000's of different characters!
So another character set was needed.
UNICODE
A 16 bit character set that can represent around 65,000 different characters - CLICK HERE
But there is an extended version that can represent over 128,000 different characters by using more than 16 bits.
UNICode is the single character set that contains all the Worlds different characters and symbole. This includes Mandarin and Arabic characters, even smileys!

WTM: A character set question
Candidates should be able to:
explain how sound can be sampled and stored in digital form
explain how sampling intervals and other considerations affect the size of a sound file and quality of its playback.
Sampling: Storing sound as sample of air pressure
Sample rate
is the number of samples of audio stored per second
CD quality is 44,100 samples per second
Bitrate
the size of register to represent each sample value (eg. CD format is 16bit so every CD sample stores a 16bit value)
The higher the bit rate the larger the number can be stored therefore the more accurate the value of the sample can be stored, but larger the file size
Channels
stereo music has left and right channels stored therefore = 2
Mono = 1
File size calculations:
File size in bits = (bit rate * (sample rate * length of sample in secs)) * number of channels
File size in bytes = file size in bits / 8

WTM: Sound sampling
Candidates should be able to:
explain the representation of an image as a series of pixels represented in binary
explain the need for metadata to be included in the file such as height, width and colour depth
discuss the effect of colour depth and resolution on the size of an image file.
The human eye
576 mega pixels resolution (estimated)
50fps (on average although evidence suggests it goes up to 150+fps)
The average person can detect around 1,000,000 different colours
The Cornea is the only body tissues that does not need a blood supply.
Question: How much space, in MB, is required in the human brain to remember a 1 minute event witnessed in real life?
Storing image digitally: Bitmaps and Vectors
Pixel
the smallest block of colour in a bitmap image
Colour depth (aka 'bit depth' - CLICK HERE for more examples
the number of different colours each pixel can be
GIF files only have a maximum colour depth of 8 bit so each pixel can only be one of 256 different colours.
24 bit colour depth is also called "True Colour". The 24 bits are made up of x3 bytes of colour information:
8 bits describing the red content (R)
8 bits describing the green content (G)
8 bits describing the blue content (B)
The resultant 24 bit number is often described by humans in hexadecimal format (eg. #b02040)
Metadata
Metadata is data about an image. Your camera can automatically store certain pieces of data about the image being taken INSIDE the image file.
Types of Metadata stored in each image:
File Format (JPG, PNG, GIF etc.)
Dimensions (eg. 960 x 720 pixels)
Resolution (the number of pixels per inch - PPI - the image is taken using)
Colour Depth (aka 'bit depth' - the maximum amount of colours that each pixel can store eg. 16 bit = 65,536 different colours per pixel)
Time/Date the image was last changed
Camera Settings when the photo was taken
GPS Data (location information - handy when viewed through something like Google Maps)
Bitmaps, vectors, file sizes and compression
Vector images are images that are described in terms of polygons.
A polygon is a shape made of straight lines that have no end of beginning. A circle is NOT a polygon (unless made out of lots of small lines)
Each polygon is described mathematically and saved as text.
The more complex the vector image, the more instructions therefore the larger the file size.
This is a red square.
It is a bitmap image.
It is 960 x 720 pixels large, so 691,200 pixels.
Each pixel has a colour depth of 24bits (so each pixel can display up to 16,777,216 number of colours.
The file size should therefore be:
691,200 x 24 = 16,588,800 bits
16,588,800 bits / 8 = 2,073,600 bytes (roughly 2Mb)
But the file size is in fact only 4Kb. Why? It is a PNG file and therefore can be compressed.
PNG files can be compressed with LOSSLESS compression (so there is no loss of quality when compressed).
JPG files can be compressed, but with LOSSY compression (so the quality of the image decreases with compression)
This is a red square.
It is a vector image.
When drawn (rendered) it will take up the same size as 960 x 720 pixels.
The instructions for rendering the image are below.
Because the image is so simple, there are very few rendering instructions. Draw a square and fill it with the colour #ff0000 (red).
Since the instructions are stored as text, and each character is stored as a 16 bit word, then the file is 597 bytes.
Vector instructions to draw the red square
Logic Gates
An uncompressed bitmap image file size will not change.
However the vector file will increase in size with every added detail.
The x3 main logic gates you need to know about are OR, AND and NOT. Here are the most common logic gates, their symbols and truth tables (the table showing what inputs result in what output):
Now we need to do something with the numbers…let’s start with adding up
To add binary numbers is simple for humans. Even a 3 year old child can add 1 and 1 together.