Binary-coded decimals and PLCs

Binary-coded decimal (BCD) is a class of binary encodings of decimal numbers where each decimal is represented by a fixed number of bits, usually four or eight, which goes against the way humans compute data. This disconnect can cause problems for programmable logic controller (PLC) users.


Binary-coded decimal (BCD) is a class of binary encodings of decimal numbers where each decimal is represented by a fixed number of bits, usually four or eight, which goes against the way humans compute data. This disconnect can cause problems for programComputers hate decimals. Just because we have 10 fingers and 10 toes, we think we can dictate what base other computing entities should think in. In fact it's really quite inefficient. It's easy to convert base 2 to base 8 or base 16, which any logical device can handle quite well. Binary-coded decimals (BCDs) are a class of binary encodings, which are usually represented by four or eight bits. It's only humans who need to add up all those individual bits in our registers to convert them to base 10 because that's the way we're programmed to think.

Back in the days before touchscreens, seven-segment displays and thumbwheel switches were used as a numerical interface between humans and programmable logic controllers (PLCs). Even before the PLC, these devices were the only graphical way to interface with circuits numerically. Users could move plugs around like in the days of ENIAC (the first electronic general purpose computer), but it was a lot easier to view and adjust decimal numbers with these devices. The problem was, they were very input/output (I/O) intensive. Each thumbwheel segment requires four inputs (+ power), while each 7-segment display requires four 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 decimals.

A common complaint is the math; every data type has to be explicitly declared on the platform, and converted if data types are not equivalent. Not only that, but the standard timer and counter data types incorporate BCD 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 seven-segment displays. In fact, the timer setpoints are still entered as "S5T#3S" for a 3-second setpoint. 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. 

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. 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 seven-segment displays will help clear up some of the mystery and "why" of BCD.

Frank Lamb is the founder of Automation Consulting Services Inc. This article originally appeared on the Automation Primer blog. Automation Primer is a CFE Media content partner. Edited by Chris Vavra, production editor, Control Engineering, CFE Media,

ONLINE extra

For more articles on PLCs and programming, see related articles below.

Thomas , OH, United States, 07/13/16 07:17 AM:

If we humans were smart enough to create a ten state electronic switching device, computers could do numbering systems just like we humans.
The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by...
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
The Engineering Leaders Under 40 program identifies and gives recognition to young engineers who...
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Make Big Data and Industrial Internet of Things work for you, 2017 Engineers' Choice Finalists, Avoid control design pitfalls, Managing IIoT processes
Engineering Leaders Under 40; System integration improving packaging operation; Process sensing; PID velocity; Cybersecurity and functional safety
Mobile HMI; PID tuning tips; Mechatronics; Intelligent project management; Cybersecurity in Russia; Engineering education; Road to IANA
This article collection contains several articles on the Industrial Internet of Things (IIoT) and how it is transforming manufacturing.

Find and connect with the most suitable service provider for your unique application. Start searching the Global System Integrator Database Now!

SCADA at the junction, Managing risk through maintenance, Moving at the speed of data
Flexible offshore fire protection; Big Data's impact on operations; Bridging the skills gap; Identifying security risks
The digital oilfield: Utilizing Big Data can yield big savings; Virtualization a real solution; Tracking SIS performance
click me