 |
 |
 |
 |
 |
|
With Hexadecimal (Hex for short) programming,
there are two ways to calculate it. The first way is similar to doing
it in Decimal. We'll show this method so you can see the relation.
But adding things up in Hex is more cumbersome than adding them up
in Decimal (simply because we don't have 16 fingers and are not use
to that system). However, calculating each Hex digit individually
(our second way to do it) is much easier than decimal. While explaining
the second way is a bit more complicated, doing it is so simple you
can quickly calculate any CV value in your head - once you learn the
trick. We'll cover that last.
Each item that is controlled in a
CV has a value. It's as simple as adding up the values for the features
you want turned on and programming that value into the CV.
CVs are made up of eight bits, numbered
zero through seven (0-7). Each of these bits has a value, starting
with bit zero (0) having a value of one (1). Each subsequent bits
value is double that of the one preceding it. Bit 1 has a value of
2, bit two has a value of 4, bit 3 has a value of 8, and so on. However,
once you get past bit 3, Hex is a little different than the counting
you're familiar with. |
 |
 |
|
Bit |
Decimal Value |
Hexadecimal
Value |
| 0 |
1 |
01 (zero one) |
| 1 |
2 |
02 (zero two) |
| 2 |
4 |
04 (zero four) |
| 3 |
8 |
08 (zero eight) |
| 4 |
16 |
10 (one zero, NOT
ten) |
| 5 |
32 |
20 (two zero, NOT
twenty) |
| 6 |
64 |
40 (four zero, NOT
forty) |
| 7 |
128 |
80 (eight zero, NOT
eighty) |
 |
|
 |
|
Yes, in hexadecimal
10 (one zero) is twice as much as 8 (zero eight) - you'll find out
why later.
If you program a zero into the CV,
all bits are turned off. If you add up all the values, you'll find
that there's a total value of FF. Programming FF into the CV turns
all the bits on. What's FF?
Well, in decimal counting, it goes
from 0 through 9 before it rolls over to 10. When adding up a column
of figures we call it "carrying the 1" . When counting in
Hex, it goes from 0 through 15 before it rolls over to 10. |
 |
 |
In fact, in Hex,
any digit greater than 9 is not called what it is called in decimal
- instead, we use letters: A = decimal 10, B = decimal 11, and so
on though F = decimal 15. Just think of A through F as a third hand
with six more fingers.
So when counting your fingers you
would count 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. Now you
carry the one and start over with 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 1A, 1B, 1C, 1D, 1E, and 1F. It then rolls over to 20, 21,
and so on all the way to FF. By the way, Hex FF is equivalent to decimal
255. |
 |
|
10 x 10 = 100 in decimal and 10 x 10 = 100 (one
zero zero) in hexadecimal. However, 100 Hex is equivalent to 256 decimal.
That's why 1 less than Hex 100 is FF, just like 1 less than decimal
100 is 99. Remember, "F" is the last number before rolling
over to 10 hexadecimal just like 9 is the last number before rolling
over to 10 in decimal. 256 is a significant number because that's
the total number of different values a single memory byte (CV) can
contain. Multiplying 100 x 100 = 10,000 in decimal and 10000 (one
zero zero zero zero) in hexadecimal. However, 10000 hexadecimal is
equivalent to 65,536 decimal. This is also a significant number. In
the early days of desktop computers, this was the maximum amount of
memory (64K) that a typical eight-bit processor could access directly.
Anyway, subtracting 1 from hex 10000 equals FFFF just like subtracting
1 from decimal 10,000 equals 9,999. |
| Let's get specific with CV29 so you can understand
this a little better. |
|
Bit |
Value |
Feature |
| 0 |
01 |
Base Direction in Reverse |
| 1 |
02 |
28/128 speed-step mode |
| 2 |
04 |
Automatic Analog Conversion |
| 3 |
08 |
Always Leave Off |
| 4 |
10 |
User-Loadable Speed Table |
| 5 |
20 |
Four-Digit Addressing |
| 6 |
40 |
Always Leave Off |
| 7 |
80 |
Always Leave Off |
 |
 |
 |
|
If you want the base
direction to be forward, you leave bit 0 off.
If you want to run in the 28 or 128 speed-step mode, you turn bit
01 on.
If you don't want Automatic Analog
Conversion, you leave bit 2 off.
If you want to use the built-in speed curve, leave bit 4 off.
If you want to use four-digit addressing, bit 5 must be turned on. |
 |
 |
Since all other bits
must be left off, the only two bits to turn on are 1 and 5. The value
for bit 1 is 02 and the value for bit 5 is 20. Notice that this example
is exactly the same as presented for the Decimal explanation of CV29.
The only difference is that the value of bit 5 in decimal was 32,
whereas here it's Hex 20. So, add 20 and 02 together to get Hex 22
(two two) to program into CV29.
Simple enough.
However, some values can involve
adding numbers together that exceed 9 (especially with SoundTraxx
sound decoders) to a point of not being able to calculate it in your
head. We'll do one here first, then present another method that will
be so simple you'll slap your head and say "duh".
CV51 in Throttle Up!'s DSD-150 Steam
SoundTraxx decoder is for Background Sound Configuration. Each bit
controls something different, as shown below. |
 |
 |
|
Bit |
Value |
Feature |
| 0 |
01 |
Real Time Clock Mode |
| 1 |
02 |
Air Pump On |
| 2 |
04 |
Blower Sound Enabled |
| 3 |
08 |
Fireman Fred Enabled |
| 4 |
10 |
Pneumatic Grease Gun Enabled |
| 5 |
20 |
Boiler Pop Valve Blow Off Enabled |
| 6 |
40 |
Automatic Cylinder Blow Down Enabled |
| 7 |
80 |
Background Sound Global Enable |
 |
 |
 |
|
For arguments sake, lets
say;
We want Real time off
We want Air pump on
We want the Blower enabled
We want Fireman Fred enabled
We want the Grease gun enabled
We want the Boiler pop value disabled
We want Automatic Blow Down enabled
Since we want all of these enabled things to work, we have to enable
bit 7. |
 |
 |
With all bits needing to be enabled
except for bits zero (0) and five (5), we have to add them all up
except zero and five. This means we have to add 02 + 04 + 08 + 10
+ 40 + 80 for a total of DE. So how do you do that? The first thing
to remember is that when adding up digits that are greater than 9,
don't forget the letter digits. Let's present it in a format that's
easier to see:
02 (zero two)
04 (zero four)
08 (zero eight)
10 (one zero)
40 (four zero)
80 (eight zero)
Now add them together. Yeah, right... From this standpoint,
it's hard to see how adding that in your head can possibly be easy
- but it is when you know the trick.
Don't look at it as adding a column of numbers and
adding them ALL together like you have to do in decimal. Just add
one digit at a time. Note that all values for bits 4-7 end with zero
(0) - that's the key. |
 |
Hexadecimal numbers programmed
into a CVs are ALWAYS two digits: a right and a left. Bits 0-3 make
up the right digit, bits 4-7 make up the left digit. Just add them
up individually and put them together to make the two-digit value.
But don't add them, count them.
For example, with our bits 0-3 example
here, we have 2 + 4 + 8. Start with the highest value first and count
the smaller ones in. Adding 4 to 8, you count starting with 8, then
say 9, A, B, C. We just added four to 8. Now starting with C, add
two more by counting D, E. We now know that the right digit is E.
Doing it this way you never have to count past F.
Let's do the left digit.
In our example, we needed to add
10 + 40 + 80. Ignore the zeros, as is already done in the illustration
above, and simply add those numbers (1 + 4 + 8). Starting with 8,
count four more into it the same way we did above - 9, A, B, C. Now
add one more, D. Our left digit is D.
Combine the left and right digits
together to make DE. Personally, I add up the left digit first, then
the right. It doesn't matter. Do it whichever way is easiest for you.
Here's another tip:
When looking in Throttle Up! technical
manuals for SoundTraxx sound decoders, you'll find that they provide
a listing of what each bit does at the top of the page, as we saw
in the illustration above. All you have to do is write the bit values
in or under each box and scribe a heavy line down the middle, as shown
below.
|
 |
The four boxes to the left of the line represent
the left digit, the four boxes on the right represent the right digit.
You really don't need to know the bit numbers. After calculating several
CVs this way, you'll start to visualize the value without even having
to count them off. But if you go awhile without doing one, you may
have to count them off again - until it comes back. Either way, it's
a whole lot easier than using decimal. |
 |
 |
| However, if the CV
you're calculating has a single value for a single control, working
in Decimal may be easier. If you think decimal may be easier for multiple
control CVs, check out Decimal Calculations. |
|
|