News

# All About Base-2 on this Tuesday, 2/22/2022

February 22, 2022 by David Peterson

## Every day has historical significance - it will never happen again. But more importantly, today contains a lineup of a LOT of 2’s. Is there a better day to talk about the language of computers and PLCs, base-2?

### Number Counting Bases

Imagine where we would be if we didn’t have thumbs… For one thing, hitchhiking would never have gotten popular. What about the little, or the ring fingers? One thing is absolutely certain about fingers, you can always count on ‘em.

Since we have ten fingers, our counting system of 0 through 9 is very natural, learned from a young age. Bigger numbers are simply combinations of those digits 0-9. We call this a base-10 counting system.

##### Rockwell / Allen Bradley BOOL creation

Computers are an entirely different story. They may be handy, but they do not have hands. Information stored in memory is stored as latchable combinations of transistors with only two possible states ON and OFF. In the sense of numbers, you cannot count 1, 2, 3, 4, 5… and so on with only two possible states. You can only count 0, 1… and that’s it. This is base-2.

### Why do Engineers Care About Binary?

Every industrial device with a CPU must store information in digital memory modules, with those two binary options limiting the flexibility of what numbers can be stored.

The data type is so common, that we assign it a unique name - the boolean, or BOOL, named after George Boole, credited with the foundation of base-2 mathematics.

##### Siemens BOOL creation

Within the scope of industry, discrete base-2 values take on a variety of different names: we might way ON/OFF as a relay output signal, or TRUE/FALSE as an optic sensor. Inside an integrated circuit (IC) logic diagram, HIGH/LOW would be the preferred states. 1 or 0 would be the representation inside a tag database in a PLC program.

### What About Integers and Decimal Numbers?

I’m glad you asked. Integers are listed with the number of discrete boolean bits they contain. 16- and 32-bit integers being among the most common for control systems. More bits yield larger capacities for storage. The integers may represent the number of milliseconds of a timer, or the number of parts on a conveyor. Decimal numbers (floats, or REALs) are also 32-bit numbers, but the function of the bits allows very large and very small numbers, both positive and negative.

### Counting in Binary

Since base-2 only contains 0 and 1, once you reach 1, where do you go? I imagine it like buckets of water. Each bucket holds 1 gallon of water, unlike our base-10 which hold 10 gallons each.

##### Automation Direct BOOL creation

The bucket starts empty, then you fill it.

0 = empty

1 = full

But you can’t fill it any more, so you must empty it into a new bucket beside it, then refill the first bucket (on the right, lowest place value on the right).

0 0 = both empty

0 1 = first one full

1 0 = empty the first bucket into the second bucket

1 1 = now they are both full

This cycle will continue with a third, and fourth ‘bucket’. The buckets, of course, simply being analogies for the bits. With 16 bits, you can create a vast number of combinations:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 = minimum

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 = maximum

### Binary Mathematics

Addition is perhaps the most important operation in all of math. Subtraction is simply the addition of a negative number. Multiplication is a series of compounding additions. Division is a series of compounding subtractions (negative additions).

To add binary numbers, the process is exactly what it is in the decimal system, however, in decimal we carry over any addition that results 10 or above.

Example: 5 + 5 = 0, carry the 1, and you get 10.

In base 2, you carry any results 2 or above.

Example: 1 + 1 = 0, carry the 1 and you get 10

A bigger example:

10

+ 11

The lowest digits, 0 + 1 simply make 1.

The 1 + 1 in the next column make 10, just like before.

Now 10 is equal to 2 in decimal, and 11 is equal to 3 in decimal, and sure enough 101 is equal to 5 in decimal. The math works out!

### Summary

Computers may be restricted in their capacity to count large values. But there is no argument that they increase our efficiency and capability in the field tremendously. A little understanding can go a long way in leveraging technology.

As long as you can put 2 and 2 together… Or maybe just 1 and 1.