Understanding Binary, Hexadecimal and Octal Numbers
Prerequisites:
- None
Understanding Decimal NotationSo, you know about decimal notation, right? It's the one you sue every day when working with numbers. Let's take it apart, to see if we can leverage what we find to understand the other types of notation-
$$123.45$$
This number is all we need to understand those mechanics. Okay, so what <em>does</em> this number mean? A hint would be to look at the "word"-form of this number - "A hundred and twenty three point four five". This number is a <em>representation, a notation</em> of the sum of the following numbers - $1\cdot 10^2,\space 2\cdot 10^1, \space 3 \cdot 10^0,\space 4\cdot 10^{-1},\space 5\cdot 10^{-2}$, which yes, are themselves are representations, but they're elementary enough for us to not need to break them down to know how they work. The exact same notation is used in every other number system
A bit of terminology
OK, before we start learning about this stuff, we need a bit of terminology knowledge. It's not much, so here we go
And that's it.
The numbering systems of digital logic
Now, strictly speaking, the numbering system for digital logic is binary (base 2), but octal(base 8) and hexadecimal(base 16) provide convenient ways of compacting the long binary numbers, so we study them as part of digital logic, in fact, you'll probably see hexadecimal the most.
But either way, let's start with binary.
The Binary System (Base 2)
In this system, we only have two digits - 1 and 0. And using the same principles that apply to decimal notation, we can understand a binary number.
Lets try this out-
$$1011$$
We know that this is base 2, so, we'll use powers of 2 rather than 10. SO you get - $1\cdot 2^0 + 1\cdot 2^1 + 0\cdot 2^2 + 1\cdot 2^1 \space = \space 11$.
Congratz, you can now understand how binary systems work, and since binary is so simple, all mathematical operations work like before - just remember than you're only allowed to use the two digits in binary system.
Just to be sure you understand, I'll leave a few example, feel free to skip ahead if you've already mastered it -
100*110 = 11000
10 + 10 = 100
100 + 1 = 101
Now, we should know how to convert from decimal to binary, since I've only taught the reverse, and this skill will be handy when building certain circuits.
Take any number, I'm gonna take 432, screw anybody who says otherwise. Now, you want to know what number that is a power of 2, is lesser than or number There are gonna be tons of them, but we want the maximum, and in our case, it's 256, so you subtract 256 from our number, so we get 176, and repeat this step, and once you've done it, you'll have a simple expression of the form - $\sum^{n}_{0} k_i \cdot 2^i \space ,\space k_i \in \{0, 1\}$
Now, this should be really familiar, after all, this form is how you converted Binary numbers to Decimal, and by reversing the procedure written above for Binary $\implies$ Decimal, we can convert Decimal numbers to Binary numbers. And that is all there is to learn about Binary for now.
The Hexadecimal System (Base 16)
In this system, we have 16 digits, 9 of them the familiar digits from the Decimal system, and 6 of the remaining digits from the English Alphabet (A through F). The only reason we use this system is because it literally compacts a binary number, every digit represents four digits of a binary number (this, by the way, only happens when the base is a power of 2, so octal system too, behaves like this, the only difference being, it represents 3 digits, try figuring out why that's the case)
$$123.45$$
This number is all we need to understand those mechanics. Okay, so what <em>does</em> this number mean? A hint would be to look at the "word"-form of this number - "A hundred and twenty three point four five". This number is a <em>representation, a notation</em> of the sum of the following numbers - $1\cdot 10^2,\space 2\cdot 10^1, \space 3 \cdot 10^0,\space 4\cdot 10^{-1},\space 5\cdot 10^{-2}$, which yes, are themselves are representations, but they're elementary enough for us to not need to break them down to know how they work. The exact same notation is used in every other number system
A bit of terminology
OK, before we start learning about this stuff, we need a bit of terminology knowledge. It's not much, so here we go
- Number system $\implies$ A way of representing numbers
- Base $n$ $\implies$ A number whose digits go from $0$ to $n - 1$, with a total of $n$ digits. The numbers themselves should scale with powers of $n$ when going beyond the value $n - 1$
- When all existing numbers have been exhausted ($0, 1, ... 9$), usually, alphabets are used (but sometimes, Greek alphabets are used like in the case of the dozenal system which is arguably better than the decimal system)
And that's it.
The numbering systems of digital logic
Now, strictly speaking, the numbering system for digital logic is binary (base 2), but octal(base 8) and hexadecimal(base 16) provide convenient ways of compacting the long binary numbers, so we study them as part of digital logic, in fact, you'll probably see hexadecimal the most.
But either way, let's start with binary.
The Binary System (Base 2)
In this system, we only have two digits - 1 and 0. And using the same principles that apply to decimal notation, we can understand a binary number.
Lets try this out-
$$1011$$
We know that this is base 2, so, we'll use powers of 2 rather than 10. SO you get - $1\cdot 2^0 + 1\cdot 2^1 + 0\cdot 2^2 + 1\cdot 2^1 \space = \space 11$.
Congratz, you can now understand how binary systems work, and since binary is so simple, all mathematical operations work like before - just remember than you're only allowed to use the two digits in binary system.
Just to be sure you understand, I'll leave a few example, feel free to skip ahead if you've already mastered it -
100*110 = 11000
10 + 10 = 100
100 + 1 = 101
Now, we should know how to convert from decimal to binary, since I've only taught the reverse, and this skill will be handy when building certain circuits.
Take any number, I'm gonna take 432, screw anybody who says otherwise. Now, you want to know what number that is a power of 2, is lesser than or number There are gonna be tons of them, but we want the maximum, and in our case, it's 256, so you subtract 256 from our number, so we get 176, and repeat this step, and once you've done it, you'll have a simple expression of the form - $\sum^{n}_{0} k_i \cdot 2^i \space ,\space k_i \in \{0, 1\}$
Now, this should be really familiar, after all, this form is how you converted Binary numbers to Decimal, and by reversing the procedure written above for Binary $\implies$ Decimal, we can convert Decimal numbers to Binary numbers. And that is all there is to learn about Binary for now.
The Hexadecimal System (Base 16)
In this system, we have 16 digits, 9 of them the familiar digits from the Decimal system, and 6 of the remaining digits from the English Alphabet (A through F). The only reason we use this system is because it literally compacts a binary number, every digit represents four digits of a binary number (this, by the way, only happens when the base is a power of 2, so octal system too, behaves like this, the only difference being, it represents 3 digits, try figuring out why that's the case)