Y13 Unit 0 - Class Structure
Y13 Unit 1 - Searching Algorithms
Y13 Unit 2 - Abstract Data Structures (HL)
Y13 Unit 3 - Computer Organization (Binary)
Y13 Unit 4 - Computer Organization (Architecture)
Y13 Unit 5 - Resource Management (HL)
Y13 Unit 6 - Control (HL)
Paper 3
1 of 2

Bits, Bytes, and Hex

Computers! Binary! Bytes! Zeros and Ones!

These are all terms that you’ve heard before, and perhaps worked with, but hopefully this unit gives you enough insight to know exactly what is happening inside your computer when the fans go burrrrrrr.

We’ll start with the idea that computer systems are made up of two main components, hardware and software. We’ll start with how software works and in future units we’ll slowly move towards how hardware works.

“Hello, world\n”

Let’s take a look at what has become the default software program to run on a computer system to make sure it is alive.

#include <stdio.h> //same as an import statement, gets printing functions

int main()
{
    printf("hello, world\n");
    return 0;
}

The syntax might be a bit familiar (this is a complete program in C), so hopefully you know what’s happening. YOU as a human with prior programming experience know exactly what this program will produce. How does the computer know what to do though?

Well, this piece of code was written on a file, let’s call it hello.c . In java, you might have called it hello.java and in python it could be hello.py . Ok, but how does the computer know how to turn words on a file into an action? Well, for computers everything is a number and every number can be represented by bytes and bits. Computers can then use bytes and bits to produce a different set of bytes and bits which constitutes as an “action”. Part of the file above can be seen as the following set of numbers.

Each character in the file has a corresponding number associated with it. This is the ASCII standard and computers use number representations like it to make sense of characters. But why do computers need to use numbers, because if they can understand numbers, why can’t they understand characters? To answer that question we’ll take a look at how a number can be represented in a computer because technically a computer doesn’t understand numbers either, it just understands 0 and 1. With 0 and 1 we can build representations of numbers and with numbers, we can be representations of characters and with characters, we can build words, sentences, and languages.

Bits

So our source file contains some code that was written with characters, those characters each represent a number. Let’s take a look at one of those characters, the letter “d”:

“d” is represented by the number 100. We can represent this number as a sequence of bits.

“d” is represented by 1100100 which is a bit weird to think about but quite intuitive once you can see the pattern. In red we have the actual binary representation and in black we can see the value for each digit in base ten(what you have used your whole life in math). Think of it as on and off, 1 being ON and 0 being OFF. The first digit starting from the right is worth 1, the next digit is worth 2, then 4 and so on. In this case the digits worth 64, 32 and 4 are ON, while all others are off. 64+32+4 == 100, which is the number that also represents “d”. So a computer will see 1100100 instead of “d” but they both mean the same exact thing.

Finally, what is a bit? Each of those 0’s and 1’s in the binary representation is one bit.

Bytes

To be very succinct, 8 bits make up one byte. We could easily stop there but instead we’re going to take a little trip down “why bytes” lane.

You’ve probably heard that some computers use 32-bit architectures and others use 64-bit. Maybe you’ve heard about 8-bit sounds or how your computer have 256 gigabytes of storage(2048000000000 bits can be stored in it!). This is because your computer reads bits and bytes.

let’s take something like a 32-bit integer:

0000 0000 0000 0000 0000 0000 0000 0000

There are 32 bits, one for each 0. What about a 64-bit integer:

0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

You get the idea.

So what’s the biggest number we can represent with a 4-bit integer?

1111

Every bit is ON, which means that if we start from the right most number, we will add, 1 + 2 + 4 + 8 and we get 15.

Let’s take a look at the biggest 8-bit number?

1111 1111 == 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 == 255

So if 1 byte is 8 bits, then the biggest number that can be represented with a byte is 255.

Let’s look at why this is significant by take a peek at an ASCII table: http://www.asciitable.com/

You will notice that the highest number in the table is 255, which means that each character in ASCII is 1 byte long. So we use bytes because it is the smallest sized amount of data that can hold enough character representations to write code.

Hex

If we take large numbers, we’ll find that its quite hard to write that many 1’s and 0’s. If we work on a 32-bit machine we would have to write 32 1’s and 0’s. Back in the Golden Days™, we used to write machine language, which we will learn more about next unit. Machine language is just bits and bytes, so it would take a long time to write anything if we used bits/bytes. Some smart folk came up with a simpler way to show digits called Hexadecimal Notation.

Two hex digits are used to represent one byte, or 8 bits. Hexadecimals range from 0 to F. Zero to what? 0 to F.

That makes little sense obviously, how have we count from Zero to the letter F?

0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
A = 1010 //The letter A is used instead of 10 because ten is a one and zero, 10 is the value two in binary 🤯
B = 1011
C = 1100
D = 1101
E = 1110
F = 1111


“I thought you said TWO hex digits make up a byte?” Yeah, I did. What happens when we combine two hex?

00 = 0000 0000
11 = 0001 0001
A1 = 1010 0001
FF = 1111 1111

By combining two Hex we can now create a byte. It’s much easier to write A1 than to write 1010 0001. We now have so many representations of numbers! We have binary which is base two, meaning each digit can have two values. We have hex which is base sixteen, so each digit can represent 16 values. We also have what you grew up with, base ten, where each digit can represent ten values.

So what is Hex FF in base ten?
255

What is Hex FF in binary?
1111 1111

What is 255 in binary?
1111 1111

What is 1111 1111 in base ten?
255

Welcome to the word of Bytes! In the next unit, we’ll continue exploring how your computer user these numbers, which can be used to represent characters in our hello.c example above, into actions that can be seen on the screen.

Video Lesson