Hi there! Here’s the first part of the series on Digital Computer Electronics. This is based on an out-of-print book from the 70s that talked about some interesting principles relating to computing and also went on to describe logic circuits and creating a SAP computer.
In this first part, we start the boring part of theory. But bear with me, it will get better in the future. For now, here’s an introduction to number systems.
Many, many years ago, people used to count in base 1. Shepherds would use pebbles to count the number of sheep in their flock. As they passed through a gate, they would transfer one pebble to another bag and if there were any left over, they knew a sheep had gone missing.
Counting in base 1 wouldn’t be very practical, though. Low numbers are okay, so counting 11 as two, is alright, but seven? 1111111…. Bit tricky. Maybe it’s easier with pebbles… Anyway, the Roman’s had a slightly better system. They realised that there was an easier way by giving some numbers their own symbols. Therefore we ended up with I for ‘one’, then II and III, but then IV and V. It made sense. V for five and IV is one away from five. Similarly VI is five add one. After that, X is the next special character. Sadly there was only a few special characters for numbers… 1984 (George Orwell’s fantastic dystopian novel) would be MCMLXXXIV… Doesn’t really roll off the tongue. Thankfully, the Hindu-Arabic numeral system was invented with gave all numbers between I and IX their own symbol, and base 10 was born (presumably because we have 10 fingers and it made more sense).
Base 10 is so called because of two factors. One: There are 10 digits available (0 through 9) and two: Each position is a power of 10. Every time we reach the end of the number list, we carry over. Think of it like an odometer in a car. You get a new car and the odometer will read 000000. Once we get to 000009 the next number to show would be 000010.
We use it every day, so it’s not much of a big deal.
Let’s look at two other number systems that are prolific in computing instead. Those are binary and hexadecimal.
Binary is the base of all computer communication. The “bi” refers to there being two states. Just like deci refers to ten states. In binary we have only 0 and 1. Think of that same odometer. It would clock up a lot faster at the beginning… After one mile it would show 000001. Another mile and since we’ve reached the limit of the number system we carry. Two miles now reads 000010. Three miles goes to 000011… Four = 000100 etc…
Binary is perfect for computers since when they encode data they generally encode it into electronic circuits which can only have two states (we’re not going into quantum computers here…) either on or off. Hence 1 would be on and 0 would be off. Some of the first computers output their code onto a panel of lights which would give the result as binary or binary coded decimal (BCD) which we’ll look at soon.
Binary can be grouped into different parts as well. For example we all know that a single 1 or 0 is called a ‘bit’. If we group together four bits, we now have a nibble. 8-bits becomes a byte and so on:
0 – bit
1001 – nibble
1001 1001 – byte
1001 1001 1001 1001 – word
1001 1001 1001 1001 1001 1001 1001 1001 – dword
In binary, each position is a power of 2. So whilst the units position is still one, the next one wouldn’t be a ‘tens’ column, but a ‘twos’ column. To convert binary to decimal you just add together all the positions where there’s a one. For example:
So 1001 would be 8 + 1, which is 9. Binary 1001 is equal to 9. As you add more digits, the numbers keep doubling. So if we convert a word from binary to decimal, the maximum value goes up.
1101 0110 in binary equates to 128 + 64 + 16 + 4 + 2 = 214.
It’s always useful to group binary numbers into nibbles. Especially when it comes to converting to hexadecimal.
Before that, though, how about converting decimal to binary? Not that hard with a technique called ‘double dabble’. This is all about division and remainders. Let’s say we want to convert the number 13 to binary, we’d divide 13 by 2, which would give us 6 with 1 as a remainder. This is our ones digit in binary. Next, 6 divided by two is 3 with no remainder. Therefore our ‘twos’ digit is a 0. Two goes into three once with a remainder of 1 (‘fours’ digit it a 1) and finally 2 won’t go into 1, so that’s the remainder for our ‘eights’ column. Therefore, 13 into binary would be 1101. You can see an example of this working on the YouTube video.
0 r 1 | READ 1 r 1 | TOP 3 r 0 | TO 6 r 1 \|/ BOTTOM 2 / 13
Since we’re going to be using nibbles a lot, it’s worthwhile learning the conversion of a nibble from decimal to binary and back again:
So what’s this hexadecimal thing? We know that decimal refers to a base or radix of 10. Adding ‘hexa’ (meaning ‘six’) gives us a radix of 16. If we look at that same odometer again, we’re going to be counting the same as decimal, but hitting 000010 will take a little longer… This is due to the fact that in hexadecimal (often referred to as simply ‘hex’) following 000009, the display will read 00000A, 00000B, 00000C, 00000D, 00000E and finally 00000F before we carry and reset.
Hex is also nicely aligned with a nibble. Taking a look at that table above, a binary nibble will be equivalent to decimal 0-15. The impracticality is that there is a reset and carry operation in there. Using hex, we don’t need a reset and carry, thus a nibble corresponds exactly to values 0 – F. If we look at that table again and add the hexadecimal values in, you can see what I mean.
This makes conversion from binary to hex incredibly easy as you can simply take the nibble and get your value.
Converting from Hexadecimal to decimal and vice-versa isn’t as easy as binary-decimal. For a start, if you have a 16 bit value like that one above, then you’re looking at trying to convert a very long sequence. C5E2 is equivalent to 50,658 in decimal… That binary digit on the left is equivalent to 32,768 on its own… Can you see why hexadecimal is used to interpret binary in computing now?
Of course, converting decimal into hex is also tricky. You can use a technique similar to that double dabble mentioned above, but you really will need to know your 16 times tables to do it well.
There’s one other system that’s fallen by the wayside called octal. As the root ‘oct’ suggests, this is a base 8 number system. It was useful when a lot of systems ran in 12, 24 and 36-bit words. Mostly used in mainframe computers, it sometimes made more sense to encode instructions in binary sets of 3. With the rise of 16, 32 and 64-bit systems, octal was pushed aside in favour of hexadecimal. There’s an article on Wikipedia that explains it well.
Binary Coded Decimal (BCD)
Finally there’s one last thing I wanted to touch on. Binary coded decimal or BCD. This is mostly used in some older systems (the NES has a BCD register and a lot of real-time clocks use BCD for storing the time/date) but it’s worth knowing as we may encounter it in our future endeavours.
BCD basically encodes each decimal digit into a nibble. This makes it incredibly easy to decode back to decimal. It is a little bit of a waste of a nibble, though. Only the values 0-9 are used. For example, the value 2,945 would be stored in BCD like this:
Definitely makes it easier to read, but those missing values from 1010 to 1111 makes it a bit inefficient, really.
So there we have it. Those are the basic number systems in computing. Binary and hexadecimal will play a big part in upcoming articles and videos, so I really did want to give you something to start from. Please let me know if there’s anything I’ve missed or if there’s anything that isn’t clear and I’ll do my best to explain further or correct any mistakes. In the meantime, please feel free to subscribe to the YouTube channel and check out this full comparison table below. Catch you later!
|Decimal||Hexadecimal||Binary||Binary Coded Decimal|
|0||0||0000 0000||0000 0000 0000|
|1||1||0000 0001||0000 0000 0001|
|2||2||0000 0010||0000 0000 0010|
|3||3||0000 0011||0000 0000 0011|
|4||4||0000 0100||0000 0000 0100|
|5||5||0000 0101||0000 0000 0101|
|6||6||0000 0110||0000 0000 0110|
|7||7||0000 0111||0000 0000 0111|
|8||8||0000 1000||0000 0000 1000|
|9||9||0000 1001||0000 0000 1001|
|10||A||0000 1010||0000 0001 0000|
|11||B||0000 1011||0000 0001 0001|
|12||C||0000 1100||0000 0001 0010|
|13||D||0000 1101||0000 0001 0011|
|14||E||0000 1110||0000 0001 0100|
|15||F||0000 1111||0000 0001 0101|
|16||10||0001 0000||0000 0001 0110|
|32||20||0010 0000||0000 0011 0010|
|64||40||0100 0000||0000 0110 0100|
|128||80||1000 0000||0001 0010 1000|
|255||FF||1111 1111||0010 0101 0101|
If you fancy watching a video version of this (it’s only a little bit more interesting) the you can view that here: