# DCC bits and bytes, how to "decode" setting CV's



## Greg Elmassian (Jan 3, 2008)

Well, i want to start this so people can ask questions. This is one of the more confusing parts of DCC since when you enter a setting, sometimes it's not a single setting, but a more complicated set of "bits".

Let's start by talking about CV's... even though they are called Configuration Variables (which they are), they are really memory storage locations in the decoder.

In order to pack the most information in the least memory, and minimize the number of CV "registers" many CV's have meaning to each DIGIT in the number stored.

That would be pretty straightforward to most people if you used "normal" numbers, which is a numbering system called "base 10", or decimal (deci meaning 10)

So each digit can have 10 values (from 0 to 10)

so 456 is 4 hundreds, 5 tens and 6 ones... 

You could make a system so that the hundreds digit meant something, the tens digit meant something else and the ones digit something else...

you could put 400 plus 50 plus 6 together and get 456.

Well, the binary numbering system is similar but only uses digits of 0 or 1 (bi meaning two)...

so why the heck didn't they make this simple?

internally a computer/processor uses binary numbers, 0's and 1's... so to conserve memory (which used to be really expensive) and to conserve computing power (which also used to be really expensive) the CV's can use binary numbers to be more efficient...

Now before you get all worried about having to learn another mathematical system, there are plenty of ways to have a small program, web site, or other user program to calculate all these bits and bytes for you.

The other good news is that the basic CV's needed to get things going are just a few.

One last bit of good news: no matter what you have been told, you DO NOT have to learn EVERYTHING to get started.


----------



## Dan Pierce (Jan 2, 2008)

Or post a question here as some of us work in 4 number systems binary, octal, decimal and hexadecimal. Been doing this for 50 years and taught classes on it.


----------



## Greg Elmassian (Jan 3, 2008)

I think next is maybe a link to a nice page showing the "innards" of base 2, but I think what will really help is some nice, online "calculators"...

With everyone having access to computing power, we should be able to find a nice selection of tools.

I have not looked, but there MUST be stuff for cell phones also.

My experience is that very few people really want to learn binary, and if they do, they do it without much prodding.

While I have likewise been doing binary calculations and programming since 1969, the tools are probably a much better way to go for most people. 

Greg


----------



## CliffyJ (Apr 29, 2009)

I'll hazard a guess then that each CV is composed of one byte for the CV number, and one byte for the value? Or maybe half-bytes for each?

I programmed in Lisp for many moons, and certain variables (if I'm understanding things) were handled in a manner similar to CV values, in that quite a number of "yes-no" values could be baked into the larger integer (or what appeared to be an integer). 

Keep it up Greg,
Cliff


----------



## Greg Elmassian (Jan 3, 2008)

Yep, every CV is one byte, although not all bits in each one have meaning.

Greg

(lisp, wow, I thought I was the only person I knew that wrote in lisp.. so you and I are probably the only guys on the forum who know what CAR and CDR mean ha ha)


----------



## CliffyJ (Apr 29, 2009)

One byte total, including the value? Or another byte for the value?

Just curious. 

In the 90's, I wrote a cad compression program that relied on a 4-bit vocabulary. This was for storage of cad "blocks," specifically Autocad. Achieved 95% compression. Like you said, storage space back then was a huge deal.

Speaking of Autocad, there are millions of folks using Autolisp, a Lisp dialect baked into Acad way back in '84 by John Walker aka Kelvin Throop, Autocad's inventor. Acad programmers are probably the largest Lisp contingent remaining. 

And yeah, CAR vs CDR, choosing the first item in the list vs everything else. The variants get hairy, like CADR. But then it went crazy, like CDDAAR, CDDADR, CDDDAR, CDDDDR... I always avoided that crap, so my code was a little lengthier. But when machines exploded in speed an space, it was obvious I'd wasted a good part of my life in worrying about program size.

Oops, I'm geezing all over your thread. Back to bytes and bits!


----------



## Greg Elmassian (Jan 3, 2008)

The register (CV) has an address in memory... you "see" that as the CV number... the contents of that address is an 8 bit byte...

I actually learned Lisp in my freshman year, not the best introduction to computer science in my mind, although also used Basic and assembly in freshman year.

Greg


----------



## Greg Elmassian (Jan 3, 2008)

There are only a few "required" CV's, and other than the long address (which needs 2 CV's) and CV29, which is the main configuration CV, all you normally have to do is punch in the number in decimal in most modern systems.

So, for example, CV2 is the starting speed, and you can use this to set the "voltage" so that going from speed 0 to speed 1 just ticks the loco over as slow as possible.


----------

