Logo: TechTrax...brought to you by MouseTrax Computing Solutions

A BIT of Information Can Go a Long Way

by Greg Chapman, MVP (retired)
Skill rating level 6.

A BIT of Information Can Go a Long Way

Ohmigod. Yet another geek wants to teach you about counting in bits. Well, no, it’s a topic I’d rather not breach because it is probably the most basic, most persistently treated topic in the computing world.

But I can’t resist. Think of my (selfish) position and the reasoning might become clearer. I get a lot of email from people asking me what this IP address means or what that two letter symbol, like “ff”, means in their BGCOLOR statement on a web page. Sometimes, the query is to interpret an error message like “Subscript out of range () -256”. And I’ve noted that people seem mystified when I tell them things like, “That error is because you’ve a continuous loop which terminated only because you used a single byte variable type to increment the loop. That’s a possible two bugs in your code.”

There’s no great secret in understanding these things, though, and I always feel slightly ashamed to receive that praise while realizing people will immediately stop hearing me when I explain that it’s merely because I can count to 255 with a 0 and a 1. So I don’t bother to explain.

Well, here’s my solution. I’ll explain it as lightly as I can without asking you to perform Base 2 or Base 16 math. There are a limited number of things you really need to know in order to understand. Being able to do binary addition or compliment of 9 operations is icing for most folks…but those ops also understand how to work with binary code.

Stop yourself if it starts to hurt. You should feel no pain but don’t feel bad if you do. It’s natural to feel that way if you’ve never succeeded at thinking this way in the past.

The History Channel

In simplest terms, it helps to know the following ancient knowledge.

First, there was the switch. Benjamin Franklin had one when he stepped out into the rain. He was merely taking some friendly advice to “go fly a kite!” His son assisted him and Benjamin came to understand a couple things in short order. He learned that lightning had electrical qualities and that improved everyone’s knowledge of that liquid called electricity. (It also took the mystification out of lightning, impressing people that it wasn’t merely a phenomenon of God’s wrath).

He also learned he needed a faster switch. Either his son was getting a little perverse enjoyment out of watching the famous statesman soil himself in the rain or the boy was simply slow to react!

Later, after Edison invented the incandescent light bulb, other inventors developed different uses for conductor elements in a vacuum. In 1921, Albert Hull succeeded in creating the first magnetron tube (Learn more about Tube history at http://inventors.about.com/library/inventors/blvacuumtubes.htm). From that work he developed a wide variety of vacuum style switches. Of particular interest to us is the Tetrode, a form of switch. The Brits probably most accurately named the device by calling it a ‘valve’. Hmmm, a valve is a switch of sorts! It’s just analog in nature!

Later, the vacuum tube was miniaturized with the creation of the transistor by John Bardeen, William Shockley, and Walter Brattain of Bell Telephone Labs. Miniature switches!

The last step was the creation of semiconductors and the microprocessor, a semiconductor collection of tiny transistors which are miniature ‘valves’ which are also switches.

And I know that two paragraphs ago I said something which raised your ire. Let’s take care of that now. I said analog, you said, “Grrrr!”.

Okay, here’s what analog means, and to save time, what binary means when we’re talking about computers.

A binary device only ever has one of two states or conditions. It’s either On or it’s Off. In the Off state, that binary device is said to have a value of 0. In it’s On condition, it’s said to have a value of 1.

An analog device can be thought of as a device with more than two possible values. In the case of valves, the conversation is always about how “On” that device really is. I mean, is it closed (Off or 0)? Is it all the way on (1)? Or is it somewhere in between (somewhere between 0 and 1)?

It’s easy to see that most things about the world are analog in nature (any expression of time is admitting some unknown point of 0 and some anticipated point of 1…errr, we hope we aren’t approaching time’s ‘all the way on’ state in the immediate future). It’s also easy to see that most of the things analog in the world are things we have no direct control over. Can you imagine being able to ask your husband to turn down the sun because it’s too bright today?

I digress. The point is that we have a history of inventions whose value to us is being able to collect a bunch of them in one miniature place and then measure whether they are on (1) or off (0) and use that information to make decisions. Appraising those device states in binary terms means we have something to work with.

The final thing to realize then is just a tiny cognitive leap. When you hear a computer geek tell you about the state of this or that bit, said geek is merely talking about the state of a single switch. That same geek may not even be aware of this fact so store that knowledge away. It’s handy for getting a little space to yourself at crowded parties.

When that geek starts talking about the contents of this Byte or that Byte, that chicken-head-chomping freak is talking about the on/off condition of precisely 8 bits or switches. Starting to see how this works?

You won’t have impressed our uber-geek yet, though. The clencher is when you reveal to that obnoxious bore that you know kbits from Kbytes (k=one thousand, although, to be binarily correct, it’s actually 1024. Don’t let it bother you yet).

Great, Chapman. Let me click this link. That’ll set your state to ‘0’, won’t it?

Sure, sure!! I understand. Just bear with me a moment more.

Now, we’re gonna learn to count. I know you can count, but I’ve got to make sure you can count to 255 with nothing more in your math tool box besides On or Off (1 or 0). The first thing to know is that this is a repeating pattern. Once you know the pattern, you know the way this works.

I’ll teach the pattern in what is known as Big-Endian format. All this means is that for any collection of bits, the one representing the highest number is shown as the left most bit. The bits whose value represent smaller numbers are on the right. It looks like this when I use 8 bits:

 

Bit 8

Bit 7

Bit 6

Bit 5

Bit 4

Bit 3

Bit 2

Bit 1

Bit 0

 

Big End

0

0

0

0

0

0

0

0

0

Little End

Also notice that we start with Bit 0, not Bit 1. That’s because our math teachers were trying to make sure we remained simpletons. You were taught to count from 1-10. That was useful but the method is actually a failure for reality. The right way to count is from 0-9, and then you add a new character to the ‘tens column’ and start proceeding from 0-9 again. If you need a picture, look at this:

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

See how that worked? Remember it. We’ll call this Decimal or Base 10 counting, the method by which you learned math.

Now, let’s see how to change the state of 4 bits in the right order to count from your idea of 0 to your idea of 15. I say it is your idea because the computer doesn’t understand 15. It only understands 0 and 1. Also remember, as we do this, every time we see a 1, we’re really talking about a switch that is turned on. And every 0 represents a switch that is off.

If it helps, think of every 1 as a switch that is you and every 0 is a switch representing your poor girlfriend. Pretty familiar, eh? We’ll call this Base 2 or Binary. Okay, here’s the pattern:

Binary

Decimal

0000

= 0

0001

= 1

0010

= 2

0011

= 3

0100

= 4

0101

= 5

0110

= 6

0111

= 7

1000

= 8

1001

= 9

1010

= 10

1011

= 11

1100

= 12

1101

= 13

1110

= 14

1111

= 15

Catch that? If you’re a musician and know your scales, you’re familiar with playing scales in different ‘modes’. Modes are tonal, of course, but they can also be thought of as patterns. The same is true with this counting method.

If you don’t see it yet, try looking at the numbers in bold as we count up

Binary

Decimal

0000

= 0

0001

= 1

0010

= 2

0011

= 3

0100

= 4

0101

= 5

0110

= 6

0111

= 7

1000

= 8

1001

= 9

1010

= 10

1011

= 11

1100

= 12

1101

= 13

1110

= 14

1111

= 15

Do you see it yet? I’ll explain it in text once and see if that helps.

My first priority is to always get back to setting that Little End bit to 0. In order to do this, I have to get it and all the bits between whichever Bigger End bit is already set to the value of 1.

So if I have 0101, and I want to get that littlest bit back to 0, I can only follow this order:

0101

0110

0111

1000

Now, take that and go back to the table. Work this for awhile. Go get a sandwich. Beer won’t help so leave that alone. Have some cookies. Look at that table again. Here’s a hint: every time the littlest bit leaves a state of 0 in that table, that row’s border is bold. Kinda gets your attention, doesn’t it?

If you’re getting bored or a light bulb just suddenly flipped on (all the way to a state of 1, right?), we can move ahead to another conceptual leap – the Bit Boundary. BeBopAReeBop, they’re Bit Boundary Good! Apologies to Garrison Keillor and Rhubarb Pie.

Did you notice what was happening everytime you got a row of 1’s with no 0’s in between? Yep, you added another bit to the Big End, just like when you normally hit 9 and add another digit in the “Tens” column (remember? …7,8,9, um, 10?)

Each time that happens, you’ve encountered a bit boundary. When you hit one of those boundaries, the conditions are right for the following to happen:

-You’re going to turn on a bit you’ve never met before

- All the littler bits (the ones to the right of the one you’re about to turn on) are going to be turned off.

So what the hell use is that? Well, watch what happens to the number every time you cross that boundary using 8 bits (you’re gonna like this!):

00000001 = 1

00000010 = 2

00000100 = 4

00001000 = 8

00010000 = 16

00100000 = 32

01000000 = 64

10000000 = 128

Hmm, I see a pattern!! This is (Oh crap! Here it comes!!) Base 2 counting. And notice that crossing the bit boundary means the number you’re looking at is exactly 2 X the number you had the last time you crossed that boundary! Cool!

And if you look at this really closely, you’ll see how I suddenly don’t have to show you how to do binary addition at all. If you need a hint and WANT to know, try this:

1000 = 8

0100 = 4

0010 = 2

+ 0001 = 1

1111 = 15

But What Does It All Mean?

Well, meaning comes from understanding and that usually comes from thought. Let’s think a little.

Internet IP addresses. Hmm, the maximum value in any of those fields is 255. That must mean the computer 1) doesn’t really know about 255 and, 2) 255 is the bit boundary at the 8th bit! That would be 11111111. To get to 256, I have to add a 9th bit…AND there are actually 256 numbers represented in those 8 bits since we started counting from 0, correct?

Remember at the beginning of the article where I was translating that error code -“Subscript out of range () -256”? Knowing that it takes 9 bits to represent the number 256, I knew immediately that someone had tried to increment some variable to the number 256 whose type is set to Byte (8 bits). You can’t directly represent a 9 bit number like 256 with 8 bits, obviously.

Hey!! You now also know why that geek at the party finally had to give up and run away. It’s simply because the number 1000 is not conveniently represented in binary. Take a look: 1000=1111101000

But, look at the number 1024 (what the letter ‘k’ really refers) to when displayed in binary: 1024=10000000000 (that’s 2 to the power of 10. You can think about that later, too, but it’s sitting there staring you in the face with all those zeroes.)

Now, you’ve got that under your chin and you can work with it at your leisure. It is important info as it is fundamental to nearly every operation performed on any computer.

If you’d like to learn about what ‘ff’ means (warning, it’s more of the same…but different), take a look at http://www.intuitor.com/counting/ and use the information there along with what you learned in this article.

 

Go up to the top of this page.
This site powered by the Logical Web Publisher™: Content management by Logical Expressions, Inc.