Thread by Rodrigo ๐๐
- Tweet
- Mar 31, 2023
- #ComputerProgramming
Thread
Programmers need to use many number bases:
๐ decimal (the โnormalโ base);
๐ binary (10011001);
๐ hexadecimal (e.g., F8F8F2).
But you don't need advanced maths for them to make sense.
Read this. ๐
You'll wish you had done it sooner. ๐
๐ decimal (the โnormalโ base);
๐ binary (10011001);
๐ hexadecimal (e.g., F8F8F2).
But you don't need advanced maths for them to make sense.
Read this. ๐
You'll wish you had done it sooner. ๐
This whole thread was inspired by a course on @brilliantorg, a platform that teaches from first principles.
They break down concepts into interactive, bite-sized lessons (like the dots above).
But now, I want to show you how to work with number bases in a very intuitive way!
They break down concepts into interactive, bite-sized lessons (like the dots above).
But now, I want to show you how to work with number bases in a very intuitive way!
Honestly, just because 2 is a small number. ๐คช
Let us start, then!
A โnumber baseโ is a specification about how to REPRESENT numbers.
The numbers, themselves, are always the same.
Right?
Let us start, then!
A โnumber baseโ is a specification about how to REPRESENT numbers.
The numbers, themselves, are always the same.
Right?
In the picture below, the left box has more dots than any other box, right?
You call that number โthreeโ in English.
You call it โtrรชsโ in Portuguese.
You call it โ3โ in the decimal base.
You call it โ11โ in the binary base.
But it is always the SAME number.
Agree?
You call that number โthreeโ in English.
You call it โtrรชsโ in Portuguese.
You call it โ3โ in the decimal base.
You call it โ11โ in the binary base.
But it is always the SAME number.
Agree?
So, a number base is just a mathematical language to give a name to a number.
And I am going to show you the rules.
For example, why is 138 written as
๐ 10001010 in binary;
๐ 212 in octal; and
๐ 8A in hexadecimal?
(If you don't believe me, believe Python ๐. ๐)
And I am going to show you the rules.
For example, why is 138 written as
๐ 10001010 in binary;
๐ 212 in octal; and
๐ 8A in hexadecimal?
(If you don't believe me, believe Python ๐. ๐)
Like I said, let us start with binary.
When you pick a number base, you pick a number.
You call that number the โbaseโ of that number base.
For example, in binary, the base is 2.
In hexadecimal, the base is 16.
But what is that base for?
When you pick a number base, you pick a number.
You call that number the โbaseโ of that number base.
For example, in binary, the base is 2.
In hexadecimal, the base is 16.
But what is that base for?
The base tells you how many symbols you can use to represent numbers in your number base language.
It's like the alphabet.
For example, the English alphabet has 26 symbols: ABCโฆXYZ.
The binary โalphabetโ has 2: 01.
What now?
It's like the alphabet.
For example, the English alphabet has 26 symbols: ABCโฆXYZ.
The binary โalphabetโ has 2: 01.
What now?
If the alphabet has the symbols 0 and 1, we can use those symbols to give names to numbers.
For example, โone hundred and thirty eightโ is 10001010.
And โfourโ is 100.
But we're getting ahead of ourselves!
Let us start from the beginning:
For example, โone hundred and thirty eightโ is 10001010.
And โfourโ is 100.
But we're getting ahead of ourselves!
Let us start from the beginning:
We could start by agreeing that โzeroโ is 0 in binary.
And might as well say that โoneโ is 1 in binary.
Now what?!
I used up all the symbols, so does that mean I can't represent more numbers?
And might as well say that โoneโ is 1 in binary.
Now what?!
I used up all the symbols, so does that mean I can't represent more numbers?
Of course that's NOT what that means!
We represent more numbers by combining 0s and 1s.
Again, โone hundred and thirty eightโ could be 10001010 and โfourโ could be 100.
So, how to determine these longer representations?
Let me show you how to do it for โfourโ:
We represent more numbers by combining 0s and 1s.
Again, โone hundred and thirty eightโ could be 10001010 and โfourโ could be 100.
So, how to determine these longer representations?
Let me show you how to do it for โfourโ:
I took โfourโ dots and dropped them in the rightmost box below. ๐
Now, this is binary, so I need to play a game with the red dots.
Every time I find a group of 2 dots in the same box, I need to get rid of one and move the other to the left.
Let us see how that plays out:
Now, this is binary, so I need to play a game with the red dots.
Every time I find a group of 2 dots in the same box, I need to get rid of one and move the other to the left.
Let us see how that plays out:
I'll pick 2 dots from the rightmost box.
Next, I'll get rid of one and move the other to the left. ๐๐
Now, the rightmost box still has 2 dots.
So I'll get rid of one again and move the other to the left. ๐๐
Are we done, now?
Next, I'll get rid of one and move the other to the left. ๐๐
Now, the rightmost box still has 2 dots.
So I'll get rid of one again and move the other to the left. ๐๐
Are we done, now?
Nope, not reallyโฆ
Now, I have 2 dots in the second rightmost box.
So, what do I do?
We get rid of one of the dots and move the other one to the left.
This is what we end up with, and we can stop now because there are no more groups of 2 dots in the same box.
Now, I have 2 dots in the second rightmost box.
So, what do I do?
We get rid of one of the dots and move the other one to the left.
This is what we end up with, and we can stop now because there are no more groups of 2 dots in the same box.
When we are done, we look at each box and use the symbol for the number of dots in each box.
The boxes with โzeroโ dots get a 0 and the boxes with โoneโ dot get a 1.
So, reading out the boxes and dots from the image above, what did the โfourโ dots become?
The boxes with โzeroโ dots get a 0 and the boxes with โoneโ dot get a 1.
So, reading out the boxes and dots from the image above, what did the โfourโ dots become?
The โfourโ dots became 00100 in binary.
But we get rid of the 0s on the left because they don't add anythingโฆ
So, how do we do this for any other base?
Instead of doing groups of 2 dots, we do groups with the size of the base!
In hexadecimal, we would do groups ofโฆ?
But we get rid of the 0s on the left because they don't add anythingโฆ
So, how do we do this for any other base?
Instead of doing groups of 2 dots, we do groups with the size of the base!
In hexadecimal, we would do groups ofโฆ?
16 dots!
We get rid of 15 dots and then move 1 dot to the left.
That's essentially the idea.
Keep bursting the dots until each box has a number of dots below the base number.
Let us do a crazy example. What is โthirty oneโ in base 30?
We get rid of 15 dots and then move 1 dot to the left.
That's essentially the idea.
Keep bursting the dots until each box has a number of dots below the base number.
Let us do a crazy example. What is โthirty oneโ in base 30?
Here are โthirty oneโ dots in a box.
We do a big group of 30 dots, get rid of 29, and move one to the left.
We are done, and we see that โthirty oneโ is represented by โ11โ in base 30.
We do a big group of 30 dots, get rid of 29, and move one to the left.
We are done, and we see that โthirty oneโ is represented by โ11โ in base 30.
As I said, this was inspired by a @brilliantorg course on Number Bases.
I'm quite impressed with what I learned by starting a course on a subject I thought I already knew! ๐ฎ
Click here to start a 30-day free trial + 20% off an annual subscription:
brilliant.org/mathspp
I'm quite impressed with what I learned by starting a course on a subject I thought I already knew! ๐ฎ
Click here to start a 30-day free trial + 20% off an annual subscription:
brilliant.org/mathspp