| When programming, you may find
that your Decimal calculation has to be converted to Hexadecimal,
or vice versa, before you can use it. Digitrax provides conversion
charts in some of their manuals; their Decoder manual for sure. Throttle
Up! provides a really nice slide chart. If you want one of these,
be sure to ask for one the next time you order a Throttle Up! sound
decoder.
However, you may want to convert
them yourself - without referencing a chart. It's not difficult. In
fact, once you know how to do it, the hardest thing will be remembering
how it starts. For this, we'll provide a clue a little later on that
will be easy to remember.
Whether you're converting from Decimal
to Hexadecimal or the other way around, just remember that you're
converting a Base 10 number to Base 16, or vice versa. What this really
means is that 10 in Decimal is 10 when you have counted all your fingers.
10 in Hexadecimal is 10 (one zero) when your space alien friend who
has 8 fingers on each hand has counted all his fingers.
The main difference is that the Hexadecimal
10 (one zero; if you hear someone call Hexadecimal 10 "ten",
they're dead wrong) represents 16 decimal digits. The extra digits
are inserted after 9, so counting is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F. From that point, it proceeds exactly like counting
in decimal, but using all 16 digits again:10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20, and so all the way to
FF.
FF is the highest value you'll ever
encounter while programming CVs, because that's the largest value
the eight bits of a CV can handle. FF, in Hexadecimal, converts to
255 Decimall.
Most of the time you'll need to convert
Decimal to Hexadecimal. We'll do that now, then convert
Hexadecimal to Decimal later.
Lets convert the Decimal value of
185 to Hexadecimal, for example.
Remembering that hexadecimal is base
16, all you have to do is divide 185 by 16: that's it, it's that simple.
185 divided by 16 = 11 with a remainder
of 9.
At this point you need to know that
all the Hexadecimal numbers involved with CVs are made up of two digits
- a left and right. In the division we just did, the quotient (11)
is the left digit, the remainder (9) is the right digit.
Notice that 11 is a two-digit value.
That means it's one of those letter numbers: but which one? All you
have to do is count from 9. If you say 9, 10, 11, that's three digits.
So instead say 9, A, B: 11 = B.
Since 9, the remainder, is a single
digit, use it as is.
Therefore, B is the left digit and
9 is the right digit. Therefore, 185 Decimal = Hexadecimal B9.
That's easy enough.
Lets convert it back to decimal.
Again, remembering that Hexadecimal
is base 16, all you have to do is multiply and add: yes, it's that
simple.
First take the two digits apart. We have a B and we have a 9.
The left digit (B) is multiplied
times 16, and 9 (the right digit) is added to that result.
Converting B to a decimal number
is just like converting the other way. If you count to B, starting
with 9, you have to say three digits; 9, A, B. So, instead of counting
up though the letters, count decimal style for three digits: 9, 10,
11.
Multiplying 11 x 16 = 176; 176 +
9 = 185.
How do you remember whether to divide
or multiply? Easy: Divide Decimals, Multiply Hex. |