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.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
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.
Controller programming; Safety networks; Enclosure design; Power quality; Safety integrity levels; Increasing process efficiency
Additive manufacturing benefits; HMI and sensor tips; System integrator advice; Innovations from the industry
Robotic safety, collaboration, standards; DCS migration tips; IT/OT convergence; 2017 Control Engineering Salary and Career Survey
Featured articles highlight technologies that enable the Industrial Internet of Things, IIoT-related products and strategies to get data more easily to the user.
This article collection contains several articles on how automation and controls are helping human-machine interface (HMI) hardware and software advance.
This digital report will explore several aspects of how IIoT will transform manufacturing in the coming years.

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

Infrastructure for natural gas expansion; Artificial lift methods; Disruptive technology and fugitive gas emissions
Mobility as the means to offshore innovation; Preventing another Deepwater Horizon; ROVs as subsea robots; SCADA and the radio spectrum
Future of oil and gas projects; Reservoir models; The importance of SCADA to oil and gas
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.
click me