Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Binary,Bits and CV's

2562 views
17 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    September 2006
  • From: Buellton,CA.
  • 97 posts
Binary,Bits and CV's
Posted by cliffsrr on Tuesday, July 29, 2008 9:16 PM

When I see talk about the first bit,second and so I get lost. Is there a good tutorial on this? On a NCE decoder sheet it lists the CV's for setting start, kick and so forth but CV 29 lists bits 0 to 6 and says 3,6 and 7 are ignored by the decoder. Somewhere I have seen statements to turn off DC analog conversion mode, subtract 4 from CV29's value. Therefor, 2 digit locos are CV29=03 and 4 -digit locos are CV29=35. The more I read the more confused I get!

If you can get through my roundhouse smoke and clear this up for me I would toot my whistle!

Thanks

Cliff

  • Member since
    July 2006
  • From: Vail, AZ
  • 1,943 posts
Posted by Vail and Southwestern RR on Tuesday, July 29, 2008 11:26 PM
I wrote what I thought was a pretty good description on another board.  It seems to be down now.  Once it is back up, I'll copy it.

Jeff But it's a dry heat!

  • Member since
    July 2006
  • From: Vail, AZ
  • 1,943 posts
Posted by Vail and Southwestern RR on Wednesday, July 30, 2008 2:52 AM

This isn't exacly in context, since it is cut and pasted from what I wrote on thread on another forum, but I think you'll get the idea:

I'll go a bit more techie, just to describe why 0-7 is proper, and whoever dreamed up 1-8 was not an engineer (in my opinion). When you start the numbers at zero, the value of each bit set to a one is 2 raised to that power. So, if bit 2 is set, the value is 4. That makes it quick and easy to figure out the values, especially as you get to 16 bit words and such.

That said, as has been mentioned, DCC systems are getting farther away from this every day, and that's a good thing. I think the user interface is still the weak link in DCC, and because the actual functions of bits and CVs in decoders is not (and probably should not) be totally standardized, it is going to be a tough nut to crack. Hence being at least a tiny bit (oops!) binary competent is a good thing.

OK, here we go....
This link http://www.nmra.org/standards/DCC/standards_rps/rp922.html is the NMRA's 'Recommended Practice' for CV's and what they mean. (I'm not sure how it is just recommended, since anyone who didn't follow it is just asking to be incompatible, but that's a different discussion.
There is a table a little way down listing all of the available CVs and what they contain. Some are madatory, some optional, some reserved for manufacturers (to put in unique stuff), etc. Following that is a text description of what each controls, and through which bits. So, looking at CV 29, bit 4 (the fifth bit), which has a value of 16 (2 to the fourth power), determines whether the speed table is set by CVs 2,5,and 6, or by CV 25. This is also in Soundtraxx's Tsumnami Technical Reference, it is easier to read there, I think. So, if you want to use CV 25 to select the speed table you make sure that CV 29 bit 4 is set. Now is the tricky bit, depending on how your DCC system shows you the values in a CV, and where a good user interface can make a big difference. I don't have enough experience with any system to know which do what, but I can generalize. Ideally, there would just be a little box to check, or something along that line, to choose this. Then it is easy. If you see the CV in HEX notation it may look a bit scary, but it is really easier than decimal. Hex translates to bits like this:

Hex number / bits / Decimal
0 / 0000 / 0
1 / 0001 / 1
2 / 0010 / 2
3 / 0011 / 3
4 / 0100 / 4
5 / 0101 / 5
6 / 0110 / 6
7 / 0111 / 7
8 / 1000 / 8
9 / 1001 / 9
A / 1010 / 10
B / 1011 / 11
C / 1100 / 12
D / 1101 / 13
E / 1110 / 14
F / 1111 / 15

Since an 8 bit bit is represented by two hex digits, you just string them back to back and you can see the bits, right in the open. Decimal is harder, because if you don't know if a bit is set or not, it is a lot harder to just look at the number and see. Here a decimal to binary calculator is handy. And the calculator in windows can do it for you. It's under accessories, if you haven't used it. Select the scentific view, and you'll see selections for Hex, Decimal, Octal (Base 8, if you care) and binary. Select what you have, enter the number, and select what you want.

Let's do an example, then. Let's say you want to set bit 4 to a one, but you don't know what is currently is. You read the CV, and it has a value of 231 Decimal (just making this up, I don't know if that is a real possibility, but it doesn't matter). Stick 231 into the calculator (with decimal selected), then select binary. It is 11100110. Bit four is not set. So, we need to add 16 to the CV, making it 247, and we're done.

I think I'll stop now and see if this makes any sense, rather than confusing anyone further!

Anyway, if it is a 2 and you want to set bit 4, it turns into 18, or 00010010 binary (see bit four set?), or 12 hex.

Have a look at CV 29 in this document: http://soundtraxx.com/documents/manuals/tsutechreference.pdf
and you can see what the 2 means (and why nothing else is set).

 

Here is the whole thread it came from:

http://www.trainboard.com/grapevine/showthread.php?t=87644

 

Jeff But it's a dry heat!

  • Member since
    September 2007
  • From: Charlotte, NC
  • 6,099 posts
Posted by Phoebe Vet on Wednesday, July 30, 2008 7:08 AM

Vail:

As you and I know, but some others do not, the only reason we use the decimal system is because we have ten fingers.  Computers, which are now embedded in pretty much everything, work in binary which does not easily convert to and from decimal.

It's long past the time when we should be teaching our youngsters basic math in Octal or hexadecimal.

Dave

Lackawanna Route of the Phoebe Snow

  • Member since
    December 2001
  • From: Trois-Rivieres Quebec Canada
  • 1,063 posts
Posted by jalajoie on Wednesday, July 30, 2008 7:51 AM
 Vail and Southwestern RR wrote:

I'll go a bit more techie, just to describe why 0-7 is proper, and whoever dreamed up 1-8 was not an engineer (in my opinion). When you start the numbers at zero, the value of each bit set to a one is 2 raised to that power. So, if bit 2 is set, the value is 4. That makes it quick and easy to figure out the values, especially as you get to 16 bit words and such.

I think I'll stop now and see if this makes any sense, rather than confusing anyone further!

"OMG" do you confuse me, I am in computer science since 1967 and at ease with binary maths I did read your post 4 time and still don't get it. English in not my primary language but still.

As an example (the way I read it) your paragraph above is true only for bit 2 the third bit and bit 4 the 5th bit, if bits are numbered 7-6-5-4-3-2-1-0 from left to right

Jack W.

  • Member since
    July 2006
  • From: Vail, AZ
  • 1,943 posts
Posted by Vail and Southwestern RR on Wednesday, July 30, 2008 10:14 AM
 jalajoie wrote:
 Vail and Southwestern RR wrote:

I'll go a bit more techie, just to describe why 0-7 is proper, and whoever dreamed up 1-8 was not an engineer (in my opinion). When you start the numbers at zero, the value of each bit set to a one is 2 raised to that power. So, if bit 2 is set, the value is 4. That makes it quick and easy to figure out the values, especially as you get to 16 bit words and such.

I think I'll stop now and see if this makes any sense, rather than confusing anyone further!

"OMG" do you confuse me, I am in computer science since 1967 and at ease with binary maths I did read your post 4 time and still don't get it. English in not my primary language but still.

As an example (the way I read it) your paragraph above is true only for bit 2 the third bit and bit 4 the 5th bit, if bits are numbered 7-6-5-4-3-2-1-0 from left to right

Yeah, I should have written 7-0, but I think that the way the original question was presented they were ordering the bits backwards.

Jeff But it's a dry heat!

  • Member since
    December 2001
  • From: Trois-Rivieres Quebec Canada
  • 1,063 posts
Posted by jalajoie on Wednesday, July 30, 2008 10:25 AM

 Vail and Southwestern RR wrote:

Yeah, I should have written 7-0, but I think that the way the original question was presented they were ordering the bits backwards.

Yes this ordering of the array is confusing to many.

Jack W.

  • Member since
    April 2008
  • From: Los Angeles
  • 199 posts
Posted by Randall_Roberts on Wednesday, July 30, 2008 10:48 AM

Of course bit ordering is dependant on the computer's architecture.  Although we usually place high-order bit first (reading left to right), we do so because this is how we do decimal mathematics.  Some computer architectures actually place low-order bit first.  Personally trying to work with such systems confuses me, but it's not like it's never been done.

Phoebe Vet; In my experience many people don't know that we rely on decimal because we have ten fingers.  I've taught numerous classes of Computer Science students who had never gained that perspective.  I've had students ask why we don't use "real" numbers. I would love to see kids in grammer school being taught hexidecimal.  As far as octal goes, it has become archaic because powers of three don't match up well with powers of two and computers' word sizes aren't architected in powers of three.

Best! 

Randall Roberts Visit http://modeltrains.about.com Subscribe to the FREE weekly Model Trains newsletter.
  • Member since
    September 2006
  • From: Buellton,CA.
  • 97 posts
Posted by cliffsrr on Wednesday, July 30, 2008 9:20 PM

Thanks for the answers (sort of ) Still confused, I have been having problems with a Digitrax DH140 which from what I can find has been discontinued. Digitrax lists CV 08 as Reset Decoder to Factory Default but on this decoder it is Not Available. On the same Decoder Manual they list many cv's with default of 000/x00. One is 006/x06. So far I havn't seen anything in these posts that clear any of this up for me. NCE lists their defaults in decimal and hex. Much easier to work with. Again I want to thank you for the replies but this old head is still not getting the whole binary thing

Cliff

  • Member since
    July 2006
  • From: Vail, AZ
  • 1,943 posts
Posted by Vail and Southwestern RR on Wednesday, July 30, 2008 9:31 PM
 cliffsrr wrote:

Thanks for the answers (sort of ) Still confused, I have been having problems with a Digitrax DH140 which from what I can find has been discontinued. Digitrax lists CV 08 as Reset Decoder to Factory Default but on this decoder it is Not Available. On the same Decoder Manual they list many cv's with default of 000/x00. One is 006/x06. So far I havn't seen anything in these posts that clear any of this up for me. NCE lists their defaults in decimal and hex. Much easier to work with. Again I want to thank you for the replies but this old head is still not getting the whole binary thing

Cliff

Cliff-

When they show a CV as YYY/xXX, the YYY is the decimal representation, and the XX is the hex (base 16) representation.  for numbers less than 10 they look the same.  So, lets take another example:

017/x11, for example.

The 17 is easy enough to understand.  The x11 is the hex representation of the same number.  The first one represents 16, the second 1.  In binary, that would be 00010001.  Bit 4 and bit zero set to one.  Which means 2 to the 4th (16) plus 2 to the 0 (1), or 17.

Now the good news.  Even if you don't have a computer interface you can download DecoderPro, and run it in the locobuffer simulator mode.  It will do all the binary math for you, and just give you the numbers you need to know to do the programming.  Or, get a locobuffer, and you don't have to do any of the math.

Jeff But it's a dry heat!

  • Member since
    February 2001
  • From: Poconos, PA
  • 3,948 posts
Posted by TomDiehl on Wednesday, July 30, 2008 9:57 PM
 jalajoie wrote:
 Vail and Southwestern RR wrote:

I'll go a bit more techie, just to describe why 0-7 is proper, and whoever dreamed up 1-8 was not an engineer (in my opinion). When you start the numbers at zero, the value of each bit set to a one is 2 raised to that power. So, if bit 2 is set, the value is 4. That makes it quick and easy to figure out the values, especially as you get to 16 bit words and such.

I think I'll stop now and see if this makes any sense, rather than confusing anyone further!

"OMG" do you confuse me, I am in computer science since 1967 and at ease with binary maths I did read your post 4 time and still don't get it. English in not my primary language but still.

As an example (the way I read it) your paragraph above is true only for bit 2 the third bit and bit 4 the 5th bit, if bits are numbered 7-6-5-4-3-2-1-0 from left to right

Remember, there are 10 types of people in the world, those who understand binary, and those who don't. Big Smile [:D]

Just don't get into BCD (binary coded decimal). Shock [:O]

Smile, it makes people wonder what you're up to. Chief of Sanitation; Clowntown
  • Member since
    July 2008
  • 1,206 posts
Posted by mfm37 on Wednesday, July 30, 2008 10:17 PM

Cliff,

As you've found out, DH140 doesn't have reset capability. It's also been pointed out that Digitrax also lists the decimal and hexidecimal values. The value with the x in front is hex. The other is decimal.

The semi-hard part will be getting your decoder back to defaults. That will depend on how many CV's have been changed. DH140 has all CV's set to 0 except CV1 and CV29. No need to read them, just go through all the CV's and make them 0 except for CV1 and CV29.

CV1 has a value of 03.

CV29 has a vaule of 06.

Fortunately, the above values work for both decimal and hexidecimal.

Martin Myers 

  • Member since
    May 2002
  • From: Massachusetts
  • 2,899 posts
Posted by Paul3 on Wednesday, July 30, 2008 10:20 PM

Seriously, why even use hex with DCC?  I've been a DCC user for almost 10 years now, and ever since we got rid of our DT100 throttles, no one in my club has used hex for anything.

What do you need to do in hex that can't be done in decimal?  There's no need to learn hex in order to program a decoder.  In the case of CV29, just use the handy reference chart in the decoder manual.  At the very least, memorize the most important CV29 decimal values.  CV29=34 (that's decimal) is the most popular one in my club.  That's a 4-digit address at 128 speed steps running forward with DC analog mode turned off.  If you want your RS-3 to run long hood forward, add 1 to the CV29 number and make it CV29=35.  Why would anyone need to learn hex to do that?  I'd say about 95% of our 1000 locos registered in our club uses CV29=34, and most members would have no idea if that's hex or decimal. 

Usually, the use of hex programming is a scare tactic to frighten would be DCC users.  In reality, hex programming and it's use is very rare in DCC these days.

Paul A. Cutler III
************
Weather Or No Go New Haven
************

  • Member since
    July 2008
  • 1,206 posts
Posted by mfm37 on Wednesday, July 30, 2008 10:45 PM
 Paul3 wrote:

Seriously, why even use hex with DCC?  I've been a DCC user for almost 10 years now, and ever since we got rid of our DT100 throttles, no one in my club has used hex for anything.

 

Paul,

 Couldn't agree more. I got rid of my last DT100 over a year ago. Can't remember the last time I actually programmed a CV with it. Every once in a while I screw up and push the knob on a DT400 while programming and put it into hex mode :(

Martin Myers 

  • Member since
    April 2008
  • From: Los Angeles
  • 199 posts
Posted by Randall_Roberts on Wednesday, July 30, 2008 11:56 PM

I might be mistaken, but I don't think there is ever a case where you need to use hex for input. when you see numbers like 006/x06 and 017/x11 just ignore the /x and  the digits after.  The hexidecimal notation is there for hard core bits and bytes geeks, and only serves to confuse the average user... hence my questions in the other thread about how Digitrax can improve user interface.  I expect computer science and electrical engineering majors to learn hex... not accountants, photographers, truck drivers, etc. etc. etc.

Best! 

Randall Roberts Visit http://modeltrains.about.com Subscribe to the FREE weekly Model Trains newsletter.
  • Member since
    December 2001
  • From: Trois-Rivieres Quebec Canada
  • 1,063 posts
Posted by jalajoie on Thursday, July 31, 2008 12:27 AM
 Randall_Roberts wrote:

I might be mistaken, but I don't think there is ever a case where you need to use hex for input. when you see numbers like 006/x06 and 017/x11 just ignore the /x and  the digits after.  The hexidecimal notation is there for hard core bits and bytes geeks, and only serves to confuse the average user... hence my questions in the other thread about how Digitrax can improve user interface.  I expect computer science and electrical engineering majors to learn hex... not accountants, photographers, truck drivers, etc. etc. etc.

Best! 

I totally agree to the above I am using a Digitrax system since the year 2000 and never used hexadecimal. First my programming was done with a PR1 computer interface and now with the Zephyr and DT400R it is decimal all the way. 

Jack W.

  • Member since
    July 2006
  • From: Vail, AZ
  • 1,943 posts
Posted by Vail and Southwestern RR on Thursday, July 31, 2008 12:34 AM
The user interface is the next place DCC can improve, in my mind.  There's no reason the functionality of decoder pro can't be resident in the system, it isn't that hard.  Just a matter of time.

Jeff But it's a dry heat!

  • Member since
    February 2007
  • From: Christiana, TN
  • 2,134 posts
Posted by CSX Robert on Thursday, July 31, 2008 1:16 AM
Although I can't thank of any situation where you have to use hexadecimal(unless you still use a DT100), I can think of at least one where it is convenient. When programming Scalable Speed Stabilization(BEMF compensation) in a Digitrax decoder, CV57 controls the intensity. If you look at CV57 as a hexadecimal number, then the left digit controls the intenisty when in an advanced consist, and the right digit controls the intensity when not in an advanced consist.

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!