Hey, I'm super, super amped because now we're going to be getting into some of the meaty stuff when
it comes to URLs.
The first thing I want to say is that URLs can understand hexadecimal values.
"What does that mean,
Clyde?"
Well, it just means that any character typed into a URL can be replaced with hexadecimal encoding for
that character.
For example, if we type "googl%65.com", then that can be used to get to google.com because
65 is the hex encoding for the letter e.
In other words, when you type that into the browser, the browser is going to swap the %65
for the character "e" and it's going to send it on.
What ðŸ™„?
I know.
That's so weird, right?
Don't believe me?
Let's hop on to the browser and let me quickly show you.
So let me prove to you that a URL can understand both hex and ASCII characters.
They kind of go hand-in-hand.
You've got hex on the one hand and you've got Ascii on the other hand.
And although they're two separate things, the URL understands both Hex and ASCII.
Good girls.
Let me make this screen a bit bigger, and let's just type in the address bar
Google...
but now instead of writing "e", I want to write %65 as I just said in the lecture.
And if we do that, and I hit return, the browser automatically converts that hex value into a character,
an ASCII character, to be specific.
Got it?
Let's jump back to the lecture.
There you go.
You saw it in action.
I'm not making these things up. But most people will just move on from here,
right?
And I don't want to. I want us to understand Hex. But what is Hex,
you may be thinking?
And that is a very good question.
It's very, very important to understand the fundamentals before you start getting more advanced in
your programming career. And don't get intimidated because hexadecimal is just a way of writing values.
In fact, it's no different from the one we use every day, and that is the decimal system.
Decimal is base ten and it's great for us humans. And it was designed that way because we've got 10 fingers,
so it makes sense that it's base ten with decimal - we can use ten unique digits to represent large
values or small values.
And I bet you can already tell me what those ten unique digits are.
Can you?
That's right.
0 to 9.
It's very unique, it's base 10 because there are 10 unique values and they can be combined to represent
huge numbers and teeny weeny little values.
Okay,
got it?
So, similar to decimal, hex just combines digits to create large and small numbers.
Well then, how is it different to decimal?
Well, hex doesn't use a set of only 10 digits.
Hex is more powerful.
Hex uses a set of 16 unique digits.
What digits does it use?
Well, it uses 0 to 9, just like our fingers, just like decimal.
And that represents 10 unique digits, ten unique values.
But over and above decimal, hex also uses the letters A to F, which represents another six unique digits.
So, you combine that and we've got Hex, which is base 16.
"Okay, Clyde it's base 16,
but what does that really mean?
Like, I still don't get it."
Well, that's okay.
Let me try and show you in a slightly different way.
Let me pick this stone up, throw it at the screen ... and let's just start from a blank slate.
Let's say we've got a decimal system and a hex system, right?
And we want to represent 16 unique values.
Well, how can we do that with decimal?
Well, very simply, we can just represent 16 unique values from writing the number zero all the way
through up to 15.
That represents 16 unique values, right?
And those last six digits, these are repeated digits.
It's just another one.
It's just another two, three, four and a five with an extra 1 or 0 placed somewhere.
We've used all those digits before in the first ten digits, and that's why this is known as base ten.
We don't ever use more than ten unique digits.
What about Hex?
Hex, as we just said, is base 16 and it uses the characters A through to F as well.
But you'll notice now that these are not repeated digits, are they?
They are six brand new digits.
And this is why Hex is known as base 16.
Okay, cool.
That makes sense.
But how do we count in Hex?
Well, counting in hex is very similar to how we count in decimal.
Once a digit becomes greater than F, remember, that's the last character in hex,
you start at zero again and increment the digit to the left by one ... heh?
(sound: well, this is awkward)
Confused ðŸ˜•?
Don't be.
It really isn't that bad.
Let me show you.
So here we've got two tables, decimal and hex. With decimal,
let's count up to 7.
How do we do that in Hex?
Well, it's got exactly the same digits, right?
So, nothing changes.
This is how we count in Hex.
Let's now count from 8 to 15.
How is that going to work in Hex? Already,
I'm sure you can figure it out.
We've got 8 and 9, which is exactly the same as decimal.
And then as we just said, we then get A through to F. All is good and well.
But now how do we do say 16 for example?
How would that work?
Well, it's not that difficult.
16 in decimals, just the characters or the digits
1 and 6.
With Hex, we start all over again, but we increment the left digit by one.
So here we actually literally have a 1, and then we start from scratch, which the first digit in hex
is 0.
So what that means is if we want to represent the number 17, keeping the left digit the same, and we
just keep incrementing by one.
Pretty straightforward, and we just keep going on and on.
"I'm starting to understand it, but how do I know if a certain number I see on a screen is Hex ... or should
it be decimal?
Like, how do I know what it is?
How do I know what characters are represented to me on a screen when I'm looking at it?"
That's a very, very good question. And let me pose it in another way.
Say we have these characters on the screen.
Am I wanting a drink ...
or am I am trying to represent the decimal number
74007760487749?
Well, to avoid confusing situations like this, you'll often see a hexadecimal number prefix.
And that prefix is kind of like a clue to us, or to software, that we are talking hex numbers.
And what's really confusing is that we don't only have one prefix, different softwares use different
prefixes.
I know it's so irritating, but let me just give you an example of a few of the most popular ones I
could think of.
Firstly, and you'll definitely know this one, we've got the hash symbol and this is also just a hex
prefix. And these are just color references in HTML.
If you've coded any web page, you would have used these a ton.
Okay.
What about another type?
0x. 0x is a common prefix in UNIX and C-based programming languages. And we get a whole bunch more.
Literally, we get tons. We get &#D which represents a Unicode character,
\x, 0h etc etc etc.
I don't want to get into that
now.
The most important one that we have to concentrate on now, is one relating to forms, because this course
is all about forms.
And sometimes when we're dealing with forms you have to deal with URLs.
So what is that prefix?
Well, that prefix is the percentage sign.
The percentage sign is used in URLs to express different characters in Hex.
I hope this is starting to make sense.
Don't worry if you not quite sure how it looks in the URL.
We're going to be looking at examples shortly. But just taking a step back, there are many different
numeral systems out there.
We know that binary is the language of computers.
Binary uses two digits - ones and zeros - to represent unique values.
We just looked at another numeral system.
We looked at decimal and we looked at hex.
And hex is often used in programming.
I don't know why, it's just the way it is.
And the community of URLs, the web, they decided that URLs should be based in hexadecimal.
So if there's nothing else you've learned in this lecture other than this, then that's okay because
it is such a good thing to know that URLs are based in hexadecimal.
That's why we could replace the %65 with the letter "e", for example, the browser did that
automatically.
It can speak one in the same language.
But anyway, now that I've introduced you to Hex, I think we can move on.
We can start getting into more complex topics.