Ever since we were little kids, we've been taught how to count, something most of us
are pretty good at especially if you're going to be watching this video, you're probably
pretty good at counting from one to 50, or even 100, if you're quite talented.
The thing is, all the counting that we do is base-10.
And that is because we have 10 fingers, at least that's what we think.
And that makes sense to me.
So we can say, hey, I want 10 things I know I want 20 things I want 30 things, something
like that, in so that is how we count, no reason to mess with it.
Except if you're going to be working with embedded systems, computers, anything like
that.
Everything there is in binary.
And then for reasons that you may or may not understand, they're also in hexadecimal.
So we're going to go over basically why base 10 is the way it is, decimal, the way we count
currently, what base two is, what hexadecimal is and why we use it.
And then you're going to understand not only how these all work together, but also how
to convert from one to the other and why hexadecimal is so darn cool.
So first things first.
Let's talk about base 10, or decimal.
So let's take a number, I'm going to randomly come up with a number, let's say 453.
So 453.
Now the interesting thing is, if you look at it, the numbers that make up our numbers
actually only range from zero to nine.
So there's only 10 actual numbers.
Once we get up to nine, instead of coming up with another number, we'll just call it
Bob, for no reason.
It's 0 - Bob, we go one zero.
So when you're looking at 453, right here, you're not actually looking at a single number,
you're looking at 400 plus 50, plus three, and that comes out to 453.
And so basically, what you have here is zero to nine.
You have here 10 to 90, and then you have here 100 to 900.
And then you just change each one as you need to.
Now the way this is broken up is you basically look at it and you can look at it top down
to make it make more sense.
And you just want to say okay, 0 to nine.
And then... what am I doing...
10 to 90, 100 to 900.
And then this keeps on going 1000 to 9000.
And you just throw in whatever numbers you want there to make what you want.
So now I have 7453.
I want 87,000 and doing that's how it goes.
So that is generally how our base 10 works.
Now to make this more generic, let's do this as 10 to the zero, 10 to the 1, 10 to the
two, 10 to the three, wow, that 10 got really ugly and ten to the four.
Now you'll notice that's the same 10 to the zero, or anything to the zero is one.
So that multiplier is then multiplied by whatever number you have underneath.
So that's three times one, that's five times 10, that's four times 100.
That's seven times 1000, 8 times 10,000.
And that's how you get 87,453.
So that is how our numbering system works.
If you understand this, it's going to make understanding binary, way easier.
So this is base 10.
And so that is 10 to the zero, 10 to the one, ten to the two, ten to three, which goes on
for infinity, ten to the five, it's always incremented by one but it just goes on forever.
Now if we're going to do binary, which is base two, it's going to be slightly different.
Now the reason we do base two is because it is what computers can think.
And they can think 01 and that's all they can think and they can't think maybe, I don't
know, stuff like that.
It's always Yes or No.
And so that is why they use binary or base two now let's look at base two.
So instead of being ten to the zero, ten to the one, we have two to 0, two to the 1, two
to the 2, two to the 3, two to the four, five, etc.
And you have to go out farther because you can't get as many values in each slot.
Instead of going from zero to nine, you can either say 0 or 1, so these are multipliers.
And then we can either choose that they are zero, or one.
So I am going to randomly put some numbers in here and I'm going to say 11011.
Now to zero is going to give me basically one to the one is two to the 2, four, eight,
16, 32.
Eh, let's just throw another one in there, oh, that's going to be a big number.
So now if I want to look at this from a decimal, the way our brain works viewpoint, I can look
at this and say one times one is one, one times two is two, zero times four is 0, 1
times eight is eight, one times 16 is 16.
One times 32 is 32.
And then I can just simply add those together, which, please don't make me do math in my
head is...
Oops, I forgot the one... is going to be 40, 56, 58, 59.
Hopefully that is right.
Let me pull up.
I didn't pull this up.
Before I need to pull this up really quick.
We actually have a binary to hexadecimal converter on CircuitBread.com and I want to double check
all my stuff before I make any assertions.
And this is also down in the description.
If you want to jump on here and check it out.
It actually can convert anything from base two up to base 26 is I think, how we set it
up.
So let me 111011 is 59!
Okay, excellent.
I did it right.
It's something I feel pretty comfortable with it.
But I do make a lot of arithmetic mistakes as well as I say the wrong words a lot.
As you've probably noticed, if you've watched any of my videos, so this is the way that
we can take a binary number and change it to a decimal number.
And that's super helpful.
But we also need to be able to take a decimal number and turn it into a binary number.
Now, I'm just going through paper like crazy.
Let's go the opposite direction.
I'm going to come up with a random number.
So 43.
Now we know that 43 is less than 64.
So we know that it's going to be less than two to the six.
So 2 to the 5, 2 to the 4, 2 to the 3, 2 to the 2, 2 to the 1, 2 to the 0, and if I haven't,
I should apologize for my handwriting.
Again.
It is horrendous.
So you knowing this is 64, 32, etc, etc.
The way we go the other direction is you say, okay, 43, it's less than 64.
So I'm going to put a zero there, but 43 is bigger than 32.
So I'm going to put a one there, and then I'm going to subtract 32 which gives me 11.
Now, I know that 11 is smaller than 16.
So I'm going to put a zero there, but it's bigger than eight.
So I'm going to put a one there, subtract it, minus eight, it gives you three.
So two to the two is four, which is going to give me another zero to two, the two is
two to the one is two, excuse me one, minus two, and then two to zero, which is one is
going to give me another one.
So 43 is 0101011.
Now, I would like to do a video later where we go through a couple more of these because
I know I'm going pretty fast.
But right now I just want to focus on the concept.
So when we were going from binary to decimal, we simply found out what each one of those
were and we added them together.
So zero times four is zero and everything else, just do some simple addition.
And then going from decimal to binary, you have to do a little bit more intuitive thinking
of, okay, that first number is, what is it smaller than in you'd have to know exactly
where to start on your binary side.
But once you figure out, okay, 43 is less than 64.
I can start right there and then just go through down the line and subtract it.
Now, this is very time intensive.
And you'll never do this in real life, there's no reason for you to do this in real life.
The only reason you should be doing this is to get a good understanding of what's going
on.
And once you have an intuitive understanding, one, you'll be able to do some of the smaller
stuff in your head quite easily.
And two, you'll be better prepared so that when you go and use a converter, you type
it in.
And you can do that quick.
Does that make sense to do that, right?
Yes, everything's great.
But you're never going to be doing this in real life.
There's no reason but understanding the concept is crucial.
So now we've talked about decimal and binary and have gone from decimal to binary binary
to decimal.
What is hexadecimal all about hexadecimal is beneficial because this is two to the six
and you're getting seven digits right there.
Now we have 64 bit computers, which means that you have 64 ones and zeros.
And I don't know about you, but I can't keep that many ones and zeros straight in my head.
Honestly, even with hexadecimal, it's still difficult.
But what hexadecimal does is it simplifies things.
And it makes what seems like a bunch of just random ones and zeros into something that's
a little bit more human readable.
And because of that, a lot of compilers when you're doing embedded systems, like with Microchip,
Atmel, now they're the same, I guess, Renesas.
Wow, I don't know why I'm listing all of these STM, NXP whatever.
Most of them do their IDEs so that it naturally, the number you put in is hexadecimal versus
decimal, which can really screw you up.
So let's go over hexadecimal really quick.
Hexadecimal is base 16.
So we were doing 10 to the zero, 10 to the one, and then two to 0, 2 to the one, now
we're doing 16.
16 to the zero, 16 to the 1, 16 to 2, 16 to the three, and frankly, I can't do this sort
of math in my head.
So that comes out to be zero to 16.
And then this is...
Oh, wow, okay, I'm really throwing myself off here.
I have to admit that hexadecimal is harder for me to do in this because the numbers are
so much bigger and I can no longer do the math in my head.
So I'm going to do some quick cheating.
16 times 16 is 256.
I should have known that and then do another 16 in there is 4096.
So you can see this gets big, very, very, very fast.
And the basic concept is the same that whatever is in each of these slots, is then multiplied
by whatever is up here, which in this case is one this case is 16, 256, 4096.
Now the challenge here is that like I said before, I called Bob.
The "what would come after nine" I called it Bob just because that's kind of a random
name I give anything.
But in reality, we need actual numbers to represent 10, 11, 12, 13 and 14, because again,
it's zero to 15 to give us our 16 digits.
Now, because most of us know the ABCs, they just decided that would be a very simple way
to represent the additional numbers.
So instead of zero to nine, it's 0 - F. 0123456789, A, B, C, D, E, F, and F is equivalent to 15.
So if I put F here, that's F times one, and so that's 15 times one, which equals 15.
But then if I put over here 16, if I put F, F times...
F times 16, which is going to be 16, less than 256.
So, what is that 240?
I really hate doing math on camera.
I get very self conscious and certain that I'm going to destroy things.
So 15 times 16...
240!
Actually one of the biggest challenges here is when you don't see any When you don't see
the letters, that's when people screw up.
So sometimes you'll see something where you're doing your, your numbers, and you'll see somebody
See, see somebody write...
33 right there, they think, Oh 33.
Sweet.
I know that that's 33.
But in reality, that's three times 16 plus three, which is a vastly different number
than 33.
So one of the things that they do to make it easier, and unfortunately, sometimes it
just defaults to hexadecimal, which is again, what happens in a lot of the IDEs out there.
But if you want to say no, I want this to be decimal, or binary or explicitly state
that is hexadecimal.
You usually put an h, b, or d, depending on what you have.
So for here, you'd have 33h to show that that's 33 hexadecimal.
Now, if you wanted that to be decimal you'd put 33d, and then binary, you can't do 33
but you at least have 1010b to make sure people don't think that's 1,010.
Now, you'll also see hexadecimal written out as 0x0033, or just 0x33.
So 0x or 33h.
That's two different ways of showing hexadecimal.
But both of them work.
And you'll see them so much that once you see this, you'll see it all over the place.
You don't think twice about it.
Now, the question is, why does this matter?
Why do we have hexadecimal when this just seems so random, and it is kind of a pain
to convert it from decimal to hexadecimal?
That's because you don't typically convert from decimal to hexadecimal, you typically
do your conversions between hexadecimal and binary, which is incredibly easy.
So let me grab another piece of paper.
So one of the beautiful things about binary to hexadecimal is binary you go two the 0,
two the 1, two to the 2, two to the 3, and that gives you 8, 4, 2, 1 as your multipliers.
And so this range, this subset right here, can give you any value between zero and 15,
which is exactly what one character in hexadecimal can do.
So, the way this is so easy is that instead of....
I'm just going to write a bunch of random ones and zeros.
And hopefully, those are super random.
And notice how I gave them a little space between each one.
Because now I can take each one of these in turn them into a very simple hexadecimal value,
that is then very easily shown.
And so instead of having to remember 01101011011111011100, I can look at this, convert it to hexadecimal
and then I only have to remember for much easier to remember numbers.
So give me a second.
I'm going to calculate these out, hopefully not embarrassed myself too bad.
This looks like it's 12, which would make this 13, which make this seven, which makes
this 11.
So in hexadecimal, this would be AB..
C...
D...
B...
7.
So I could write all of this crazy stuff, which I already gonna forget.
And then I can just look at this B7DC, it sticks with your mind so much better.
It's so much easier, much more compact.
And that is why hexadecimal is such a big thing.
And again, doing conversion from hexadecimal to decimal, it's not a big deal.
You don't do this stuff manually.
You use converters.
So if you've need to do it, it's pretty, pretty simple, straightforward.
There's no reason you should have to do it manually.
However, going from binary to hexadecimal is so simple, that you can very, very easily
do it by hand and it's very intuitive and It just makes things a lot better for embedded
systems.
So that's it.
Hopefully that explains not only why we need to worry about binary and hexadecimal, but
it also explains our own numbering system of base 10, decimal system, and how we can
move between all of them seamlessly flawlessly and easily.
If you have any questions leave them in the comments below or go to CircuitBread.com and
put a comment there or read our write-up there.
If you liked this video, give it a like, subscribe to our channel and we'll catch you on the
next tutorial.