Binary People: Learning your 1's and 0's

Introduction 

"There are 10 types of people in the world: Those who understand binary, and those who don't."

If you don't get this joke then hopefully by the end of the chapter you'll get a chuckle out of it. You see, in the binary number system 10 = 2. How? Consider if you had no choice but to count with only a zero or a one. Pretend that the evil goblin of number snatchers had taken every number from two to nine. How would you count anything? You'd have to do it like 0, 1, 10, 11, 100, 101, 110, 111 and so on. You get the point?  Therefore, if you had three apples then the third apple would be designated as 10 when in reality you only have three apples to eat.

When it comes to computers and therefore PLCs they can only store in memory a 0 or a 1.  That's the beauty of our digital age, it's either "on" or it's "off".  Those memory chips in computers are actually made of rows upon rows of circuits that are either on at some voltage or off at some voltage.  Therefore a computer at it's very basic level can only count using a 0 (off) or a 1 (on).

That's why it's called binary because there are only two numbers like there are only two wheels on a bicycle.  The number system we are used to using is called decimal (dec = 10) and therefore we get to use ten numbers from 0 to 9.  When you think about it, it's truly arbitrary how we count.  You could also use an octal system (by 8) or hexidecimal (by 16) numbering system which we'll talk about a little later.

Base 10: An Old Familiar Friend 

Let's start off by looking closer at our all too familiar base 10 decimal system and then compare it to binary.  Decimal, like all these other number systems, is based on place-value system.  This means that the value of a digit depends both on the digit itself and it's position within the number.  The following figure shows the weights of a decimal number broken down into columns.

 

Place-Value number systems
 
That much is obvious right?  So with a number like 9876 we add it up like this: 
 
01-01 combining digits with column weights

 

The value of the number is computed by multiplying each digit by the weight of its position and adding up the results. 

Now for Binary People: Learning your 1s and 0s.">Binary

Remember that for a base 10 system the weights are 1, 10, 100, 1000 and so on.  For a binary system the weights are 1, 2, 4, 8, 16, 32, 64, etc.

01-03 place value number systems for binary
 
To figure out the value of a binary system we do the same as with the decimal but with different weights. 
 
01-04 combining digits with column weights binary
 
The base of the number is usually expressed in a subscript so that in our examples 111112 = 3110 and 101012 = 2110.  It sure is a little cumbersome to count in binary but at least it's easier then Roman numerals Laughing.

Word, Byte and Bit

What do you call a group of binary digits?  The geeks who first thought this stuff up decided to call a binary digit a bit (b-inary dig-it).  This is not to be confused with Tim-bits.  After some time they decided that it would be good to call a group of 8 bits a byte.  Funny bunch of geeks that they were the term nibble became used for 4 bits being a subset of byte.  Finally, a group of 16 bits are referred to as a word.  Here's a picture to drive home the point.

01-05 word bytes bits
 

Cheating with a Calculator

Unless you're a glutton for punishment a standard scientific calculator switches between the different number formats with ease.  In fact there's one built into the Windows operating system that typically lives under the Start button | All Programs | Accessories.  Pull down the View menu and select "Scientific".  I've highlighted the area below where you can switch between hexadecimal, decimal, octal and binary.  Very handy even for doing math and logical functions (i.e. AND, OR, etc.).

 

Scientific Calculator

 

 

 


While octal is not as common

While octal is not as common as it's cousin hexadecimal portable generator review it is still used in various PLCs so it's important to grasp the concept.