Monday, 11 June 2018

It's More than 1 to 10 - Number Systems

Well, here I am back at University, and almost coming up to exam time (and it is the first exams that I have sat in something life fifteen years, and the first maths exam in something like twenty). Even though I might have been writing a lot of history and literature, one thing somebody said once was that one way she studied was to write about the important things in a blog, so here I am, with my first post on Computer Science, and we will be looking at something that is lovingly referred to as number systems.

Okay, I'm probably stating the obvious here, but computers don't think like us. For one thing they think in terms of ones and zeros, true and false, on and off. We don't, but then again that is because we are weird. Now, I would suggest that the reason we have a base 10 number system (in that we count from 0 to 9, and then start back where were began) is because he have 10 fingers (and thumbs) on our hands. However, in reality people throughout the ages counted in a wide variety of ways. While the suggestion is that we use base ten is because we have ten fingers (and thumbs), there are cultures that include the toes, the elbows, and the wrists. Hey, they might even include all the hairs on their head. Oh, and you know that round thing with hands that hangs on the wall:


Well, that actually works on a few number systems. Initially it is a base 60 system (that is for minutes and seconds), then it shifts to a base 12 (or base 24) system, and after that it then gets really weird. However, notice how what happens is that after 60 seconds it shifts another digit and returns to 0, and after 60 minutes, it once again shifts another digit and returns to 0. Finally, after 12 (or 24) of these shifts it once again returns to 0.

Now, let us return to the initial idea, and that is the way computers think. Remember, they basically think in terms of on or off, true or false, 0s or 1s. This is called binary, namely because there are two states. As such, for computers to count, they need to count in a way that basically uses only these two states. So, this is how it has developed:

Notice the pattern. First notice how when the binary system ticks over to a new column it is a power of two - so it ticks over to two columns at 2, three columns at 4, four columns at 8 and so on. This is actually a similar pattern in our base ten system in that this system ticks over to new columns at every power of ten. (0, 10, 100, 1000 etc).

Now, this is important because it is one of the reasons we simply cannot convert binary numerals into a readable base ten system, namely because it isn't compatible with a base 2 system. Yet there is a problem in that us humans find it pretty difficult to read a base 2 number system, which is while more readable systems have been developed - base 8, or octal, and base 16, or hexadecimal, which may ring a few bells. Note how these two number systems are more compatible with a base 2 system. As such, look at how the numbers convert below:



Notice how with the hexadecimal, when we hit 10, we start using letters. This is because the number system doesn't clock over until we hit 16. Notice also with the octal that when we hit 7 it then clocks over to 10. That is because the numbers 8 and 9 don't exist in this system.

Converting the Buggers

Okay, we could try to remember all of those numbers, and while it might be a trick we could do at parties (though I probably wouldn't encourage anybody to do it, unless it was a party full of computer scientists and the like), there is a much easier way that doesn't involve excessive brain power.

Okay, I know, you can always flip open the calculator on your computer and switch it to programmer mode (and while the argument that you may not have access to your computer after a nuclear war, you will probably have more important things in mind after a nuclear war than converting numbers to binary and vice versa).



So, watch this little trick. Let us convert a random number, say 345, to binary. What we do is we divide the number by two, and if you get a remainder you mark it down as a one, and if you don't, you mark it down as a 0 (for instance, if you divide 15 by 2, you will get the answer 7.5, or rather 7 with 1 remainder, which means you note it as a 1, while if you divide 6 by 2 you get three, with no remainders, so you mark it down as a 0). Also, note that the first number is the least significant bit (LSB), and the last number is the most significant bit (MSB).


Now, we read out the number from the most significant bit to the least significant bit.

101011001

Converting it to octal and hexadecimal works as follows:

With octal we split the numbers into groups of three, and hexadecimal into groups of four (as follows)


So, with the Octa the number is 531, which in Hex it is 159.

Converting the Buggers Back
Now, there are a couple of ways to convert the numbers back to binary, and the following method is the one that I tend to prefer (okay, by preferred method is to plug the number into a calculator, but unfortunately that method is not always available).

So, you notice what we did here. Every column is a power of two, and if the column contains a 1 you multiply that power of two by one, and if it contains a 0 then you multiply it by 0 (which gives you 0). You then add the numbers up and you will have your answer.

The same method also works for other number systems - including Octa and hexadecimal, as follows:
Anyway, that is probably enough so far to make your head hurt, a lot, so we will leave it here and next time we will look at how we can play with these numbers.


Creative Commons Licence

It's More than 1 to 10 - Number Systems by David Alfred Sarkies is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.This license only applies to the text and any image that is within the public domain. Any images or videos that are the subject of copyright are not covered by this license. Use of these images are for illustrative purposes only are are not intended to assert ownership. If you wish to use this work commercially please feel free to contact me

No comments:

Post a Comment