THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
 in Andy Leonard (Entire Site) Search

## Andy Leonard

Andy Leonard is a Data Philosopher at Enterprise Data & Analytics, an SSIS Trainer, Consultant, and developer; a Business Intelligence Markup Language (Biml) developer and BimlHero; SQL Server database and data warehouse developer, community mentor, engineer, and farmer. He is a co-author of SQL Server Integration Services Design Patterns, and author of Managing Geeks - A Journey of Leading by Doing, and the Stairway to Integration Services.

# Some Logic: The Four States of Two-State Logic

Introduction

Back in the day (when years began with "1"), I was an electronics instructor at ECPI for a while. I absolutely loved this job! You can learn a lot of logic when you study electronics. And one of the fascinating facts about logic is: There are four states to two-state logic.

"What?"

I had the same response. So let's back up a minute and think about it.

What is Two-State Logic?

Two-state - or binary, or Boolean - logic is the stuff of 1's and 0's. Hence the name "two-state." Depending on how you wish to express them, the two states are:

• 1, On, High, Hi, H
• 0, Off, Low, Lo, L

"Yeah Yeah, We Get It. The Other Two States?"

The other two states are Don't Know and Don't Care. Don't Know is usually represented with a question mark: "?"; Don't Care, with an "X". Where would you use these?

Don't Care

Don't Care is the easiest to explain so let's start there.

Binary logic can be used to represent higher base-number systems such as hexadecimal (base-16) and decimal (base-10). BCD (Binary-Coded Decimal) represents base-10 numbers using binary (base-2) logic. How does BCD work?

 BCD(Base-10) Binary(Base-2) 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001

With these 10 representations, we've covered the numerals in base-10. What about the remaining combinations of Binary numbers? What about 1010, 1011, 1100, 1101, 1110, and 1111? We Don't Care.

One way to represent this in a diagram is:

 BCD(Base-10) Binary(Base-2) 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 X 1010 X 1011 X 1100 X 1101 X 1110 X 1111

When designing logic, X's (Don't Care's) can be treated as either 1's or 0's. This is convenient for simplifying logic expressions through Boolean algebra, Karnaugh Maps, or even manually.

Don't Know

Don't Know is tricksy. Sometimes, Don't Know is an indication that you haven't finished the logical design; your current I/O doesn't allow enough states. Sometimes, Don't Know can be akin to NULL in a database. Unlike Don't Care, Don't Know's cannot simply be toggled at will to simplify the expression - they must either be solved (defined) or worked around.

If I find a Don't Know completely surrounded by one value or another, that's a clue. The Don't Know is probably that value.

Conclusion

There really are four states to two-state logic (I can't make this stuff up!).

:{> Andy

Published Thursday, January 28, 2010 8:00 AM by andyleonard
Filed under: ,

#### ken ambrose said:

I've learned never to design attributes as two state logic.  No matter how vociferously the users claim there will never be any other states to their data, it is never true.  The ability to persist information about WHY data is missing, or WHY it is not applicable, or additional states or conditions not considered in the orignal analysis, always ends up being important in recording the facts or states of a domain over time.  Four state logic also totally eliminates the need and rationale for allowing nulls, and all the accompanying confusion and hassle that users and stakeholders experience trying to make sense of nulls in databases  after the DB has been in use for a while.

January 28, 2010 6:08 PM

#### Stephen Munson said:

Wow... It's really amazing that you can somehow change a single bit into 4 bits, and suddenly you have only 4 state logic instead of 16 states...

I'm hoping you'll think it through, but binary is ALWAYS JUST two-state logic - end of story.   If you have to add bits to get to describe your four-state deal, you no longer are describing binary logic by itself.  You're describing multiple-bit binary, and the only way to get 4 states is with exactly 2 bits.

In electronics, the ONLY way that a number of states is used to describe a logic gate is for a single bit, or signal.   The moment you combine more than one bit or signal into something with meaning, you no longer are describing something any electrical engineer would use the word states to describe, unless he/she would name the number of states represented by the 2 to the power of the number of bits.

Thus your example is a bit flawed in how it uses a 16-state object to describe 10 meaningful states and 6 meaningless ones, and then calling this 4 states.  Call it semantics if you wish, but if that's how you choose to make viable arguments, you could as easily argue that a nuclear bomb going off is as meaningless as an empty emotional relationship.

Time to give this one a LOT more thought...

January 28, 2010 7:19 PM

#### Karen Lopez said:

I'm supporting a model right now that has all flags implemented as a char() for the same reason. I think this discussion is more about the fact that there are many reasons for NULL and has little to do with bits.

Data can be null because it doesn't apply or because it is unknown.

So in theory you could have the same extra two states on an integer or varchar column as well.

Karen

January 29, 2010 8:19 AM

Wow, I love it when people just completely miss the point... By the way, Andy, I believe Chris Date identified not just two, but 14 different types of missing information. Might want to read some of his articles on the topic.

January 29, 2010 2:24 PM

#### Paul Nielsen said:

Excellent post Andy!

January 29, 2010 2:44 PM

(required)
(required)
Submit

#### Archives

 Privacy Statement