Have you ever thought why when we are counting, say sheep, we count up
from none to nine, and then run out of new numbers, so we put in a one
over on the left, follow it by a zero, and then count 1 0
1 1 1 2 1 3 and
so on?
Clearly this is because we have ten fingers. Pretend for a moment that
you were born with a rare disease that endowed you with sixteen fingers.
You would then count
0, 1, 2, 3, .. 9, er-umph what next?
This is how hex works. But instead of going on er-umph what next,
which is ugly, we carry on A, B, C, D, E, F. And then we have
run out of fingers. So we put a one over on the left, follow it by a zero,
(10) and then count 1-1 1-2 1-3 and so on up to 19, 1A, 1B, 1C, 1D, 1E and 1F.
We go 20, 21, 22, .. 29, 2A, .. 2F, and so on.
Just to check that you've got the idea, what happens after we reach
99 ? Yep, you guessed it, we go 9A, 9B, .. 9F, A0, A1, A2 etc. And what do
we find after FF ? Yes, 100, 101 and so on up to infinity.
Why you need to know hex
For many reasons, numbers that are used by machines can easily
be shown as hex numbers. So easy is this that, in fact, the
standard is in many cases to use hex! Most machines nowdays can
show about 16 million colours. These colours are made up of two hundred
and fifty six shades of red, 256 shades of green and 256 shades of blue.
We know from very basic high-school physics that white light can be
produced if we combine the same amounts of red, green and blue, so
it won't surprise you to learn that (red=255, green=255 and blue=255)
makes up the colour white.
Here comes the trick. If you followed our note on hex above, you
may have worked out that hex FF is the same as plain old 255 (base ten).
So a cute way of showing the colour white would then be:
red=FF green=FF blue=FF.
In HTML, this is just:
#FFFFFF
The convention
is that the first two hex digits tell us about
how much red there is, the next two, how much green, and the last two,
the amount of blue.
You can also work out why we only count up to 255 when we said that
the machines could show 256 colours - we start at zero! And
knowing this you can work out what black is:
#000000
Why all this fuss?
Think about it - you can now colour text any one of over sixteen million
distinct colours!
|