Why BCD?

Courtesy of zen.co.uk
Courtesy of zen.co.uk

Computers hate decimal. I mean, just because we have ten fingers and ten toes, we think we can dictate what base other computing entities should think in. Well, it’s really quite inefficient when you think about it, its so easy to convert base 2 to base 8 or base 16, which any logical device can handle quite well. Its only those humans who need to add up all those individual bits in our registers to convert them to base 10.

SevenSegDecoder

Back in the days before touchscreens, seven segment displays and thumbwheel switches were used as a numerical interface between humans and PLCs. Even before the PLC, these devices were the only graphical way to interface with circuits numerically. Sure, you could move plugs around like in the days of ENIAC, but it was a lot easier to view and adjust decimal numbers with these devices.

Omron Thumbwheel segment
Omron Thumbwheel segment

The problem was, they were very I/O intensive. Each thumbwheel segment requires 4 inputs (+ power), while each 7 segment display requires 4 outputs (+2 power connections). Still, it was a lot easier for most of us human types than using pushbuttons and pilot lights to interface directly with signed or unsigned integers in decimal. Or dealing directly with hexadecimal!

Binary vs. BCD
Binary vs. BCD

Last week I taught a Siemens PLC class in Portland, Oregon (This week I am in Baltimore doing the same). One of the complaints I often get when doing Siemens training is the math; every data type has to be explicitly declared on the S7 platform, and converted if data types are not equivalent. Not only that, but the standard timer and counter data types incorporate BCD (Binary Coded Decimal) into their data structures. This is because the structures go all the way back to when people had to deal with things like these thumbwheels and 7 segment displays. In fact, the timer setpoints are still entered as “S5T#3S” for a three second setpoint; this goes back to the S5 PLC platform. The timer uses three BCD digits (12 bits) and two extra bits for the time base. This is also true for the counters, meaning that they only count from -999 to +999.

The table above illustrates what that really means. Each four digit section can only carry bit values from 0000 to 1001; for the next value, rather than indexing to 1010, (“10” in signed or unsigned decimal or “A” in hexadecimal), the next bit gets bumped to the next section of bits. This means that the last six combinations of bits (A-F) are effectively wasted, not possible in the BCD structure.

The BCD structure or base is also still usable in many of the newer touchscreens, but most programmers tend to choose an integer base to express decimal numbers. The problem I have seen is that BCD is sort of like DOS; engineering schools still touch on it, but people really don’t know where it comes from. Hopefully referring back to those old thumbwheels and 7 segment displays will help clear up some of the mystery and “why” of BCD!

Share
About

Electrical Engineer and business owner from the Nashville, Tennessee area. I also play music, Chess and Go.

5 Comments on “Why BCD?

    • I do not think computers ‘hate’ anything. We (humans) designed computers to use binary logic because we (humans) don’t know how to build a 10 state transistor. BCD is just a way to more easily transfer information to us (humans) while leaving 33% of the computer’s power untapped.

  1. Just to say that something is not correct between electronic circuit picture and Bynary vs BCD table.

    In electronic circuit, A signal is less important.
    In table is the most.

    Am I having some trouble?

    • Hi Paolo,

      No, you are correct. They are from two different sources online and are only meant to represent relative positions, not MSD/LSD. Selection of A-D is arbitrary. That being said, the A-D is on the Hexadecimal side, not the BCD side, which is labeled “B1-B5”. Thanks!

  2. I agree with Thomas computer don’t hate decimal they just work with two states on/off or 1 zero. BCD make the numbers more intuitive to humans. Back in the day some main frames worked with BCD as in EBCDIC encoding. I am also told that many calculators used BCD although I have no of knowing if this is still or ever was true.