If you are like me then you know what it’s like to learn a little bit here and a little bit there but to not really know anything properly and completely. This is why I have decided to dedicate myself to learning from the ground up how computers and programming languages really work and have evolved through time.

I came to the conclusion that where better to start than going right down to the lowest level possible (unless you want to be writing pure binary) and then working my way back up from there. My thinking behind this is that I will then have a better understanding and appreciation of concepts as I rise back up the ladder to the higher level languages.

I will be using the Assembly Language Adventures: Complete Course from Udemy to work through initially and then will move on to whatever else I find next to expand on my knowledge and ideas. My goal is to write a similar program at each level of abstraction (from low level to high level languages) so I can get a comparison of my understanding at each level.

Why am I documenting this here? Well, for me I find it easier to consolidate learning and thoughts in my head if I have written it down somewhere. It also gives me somewhere to look back on in the future when I have forgotten something and it also opens it up to the world to comment and correct me where I have misunderstood something along the way.

It may be that you also find this useful in some way – only time will tell!

Numeric Bases

The first thing we need to do to learn Assembly Language is learn some basic concepts about numeric bases. In most of the real world we use a Base 10 numeric system also known as Decimal. Computers however only understand and can count, divide, multiply etc. in Base 2 which is known as Binary. In theory we could use any numeric bases such as Base 3, Base 4, Base 5 etc. but our human brain has an easier time understanding the Base 10 numeric system. Some theory says that this is because we have 10 fingers and so it evolved from there. Funnily enough you can actually count to much higher numbers using our fingers using Binary than we can in Base 10 as can be see here.

What this means in practice is that the base being used equates to the amount of symbols used. For example, Base 10 is so called as there are 10 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. Binary therefore only has 2 symbols: 0 and 1. In Base 4 we would only have 4 symbols: 0, 1, 2 and 3. You may also have heard of the Hex numeric system which is Base 16. We obviously don’t have 16 numbers in the English language so instead letters are also used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F.

How are numbers represented?

For me, the easiest way to understand this is to split each position into columns and write the columns power at the top. This means that in Base 10 each column is an additional power of 10. Therefore, the first column is 1, the second is 10, the third is 100 (10 x 10), the fourth is 1000 (10 x 10 x 10 or 10 ** 3) and so on. In Base 6 the columns would be powers of 6, so 1, 6, 36, 216 etc. This makes binary particularly easy as the column number representations are just doubled each time: 1, 2, 4, 8, 16, 32, 64, 128 etc.

Base 10 (Decimal)

Let’s take a look at the number 25,250 in Base 10. We have 5 positions in our number so first let’s write our column headers as below (increasing powers of 10):

10,000 1,000 100 10 1

We can now put our numbers into each column so we end up with the below table representation:

10,000 1,000 100 10 1
2 5 2 5 0

In the example above you can see we now have 2 counts of 10,000, 5 counts of 1,000, 2 counts of 100, 5 counts of 10 and 0 counts of 1. If we add this all together we then get the number 25,250.

We can now take this practice to work out any numeric bases, so let’s try with a few.

Base 2 (Binary)

As we said previously binary is a Base 2 numeric system so this time we need to write our columns in powers of 2, such as below:

128 64 32 16 8 4 2 1

Now let’s take a binary number and we can easily work out it’s Base 10 representation, let’s try 10011010. Again, we write out our column headers and then fill out each digit appropriately:

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

Again, we can simply add the numbers together to get the presentation, in our case that would be – 128 * 1 + 64 * 0 + 32 * 0 + 16 * 1 + 8 * 1 + 4 * 1 + 2 * 1 + 1 * 0 which gives us 158.

So now we know that to tell a computer we want to do something with our Base 10 number 158 we need to represent it to the computer as 10011010. Each digit in the binary representation is known as a binary digit or bit for short, so we can say that the number 10011010 is 8 bits or 1 byte (8 bits is known as a byte).

Base 4

Now let’s try and work out how to represent numbers in Base 4 just for some fun. We know now that in Base 4 each column would be represented by powers of 4 and that we can only use 4 symbols (0, 1, 2 and 3) so let’s start with the columns:

64 16 4 1

Now let’s say we had the number 3201 written in Base 4 (remember we don’t have any symbols above 3), we could work out what this in Decimal below:

64 16 4 1
3 2 0 1

We can see that we have 3 * 64 + 2 * 16 + 0 * 4 + 1 * 1 which would give us 225. Easy right?

Base 16 (Hex)

The last one we will look at is Base 16. We are looking at this as it is another prerequisite for learning Assembly Language as we will come across it a lot. Base 16 is also used quite a lot in computing so it’s nice to have some knowledge of it. If you’ve ever worked with colours you’ve definitely come across Hex before – ever wondered what #FFFFFF represents? Well soon you will know!

Let’s take 6 columns so we can try and represent a Hex colour and convert it to decimal. Again, we write our columns along the top, this time represented by powers of 16:

1,048,576 65,536 4096 256 16 1

As you can see the columns represent much bigger numbers now! Now let’s use the colour #FFFFFF which represents white in the online world. Remember, as Hex is a Base 16 numeric system, once we get above 9 we start representing numbers using letters up to F (if we were working in Base 17 we would also need the letter G). First, let’s map out our colour into our columns below:

1,048,576 65,536 4096 256 16 1
F F F F F F

F in Hex or Base 16 represents the number 15 so to calculate this number we need to do 15 * 1,048,576 + 15 * 65,536 + 15 * 4096 + 15 * 256 + 15 * 16 + 15 * 1 which gives us the number 16,777,215. Now we know why there are only 16,777,216 available colours to use on the web (the number we calculated plus 0 – represented by #000000).

Conclusion

I hope you have enjoyed this whistle-stop tour through the different bases and how to write numbers using any representation of your choice. We’ve also discovered why the web is limited in it’s choice of colours and also how to convert any base system back into our real world Base 10 Decimal representation extremely quickly and easily.

Let’s move forward now to the wonderful and exciting world of Binary Maths.