Bits: Beyond Numbers

The atom has taught me that the little things do count – most

Sri Chinmoy

bit (short for binary digit) is the smallest unit of data in a computer. A bit has a single binary value, either 0 or 1

As promised in my last post, we will dig into the theoretical knowledge required more directly, and I will only reference history once in a while. I will separate the first two posts into another series that I do plan to continue at some point. If interest is high in the history-driven version, I will reconsider continuing the story earlier than “at some point”.

(computing) bit synonyms: boolean, binary value

A bit

How do we represent a bit? In modern computing, depending on the programming language used, it is either something called a boolean type (false/true) or a numeric type taking only the values 0 and 1. We can arbitrarily choose hilarious alternatives of representation in our theories. For now, let’s stick to known conventions and examine the numeric version to study their properties.

How is a single bit used? Bits are values; they don’t perform actions. However, as we have for millennia, we can assign meaning to things. Values are easy targets for this approach. We know bits can take the value of 0 or 1, so we can assign names/meaning to these two states.

We can, for example, store answers to yes/no questions: Does Mary have a little lamb? Is this number prime? Is this pixel white? The way we would do this is to designate “1” as representing “yes” and “0” as representing “no.” So if Mary sold her little lamb for profit and no longer has it, the answer to the question “Does Mary have a little lamb?” in its bit form would be “0.”

Boooring! Wait, there’s more. Can we use more than one bit? We sure can. Modern programs use more than thousands of millions of bits in their operations. But let’s start small.

Multiple bits

What could we do with two bits? We can answer two yes and no questions, but that’s still not exciting. We know that each bit can be either 0 or 1, so let’s list all the possible pairs of bits that wecan represent:

If one bit can have the values:
0
1

One way to obtain all the possible pairs by first putting a 0 and then a 1 in front of the possible values of a bit (we will learn other methods later).
[0, 0]
[0, 1]
[1, 0]
[1, 1]

(we will use this [] notation for grouping things together, other common notations use {} or even ())

If we were interested in all the possible values for a group of 3 bits, we could repeat the same process, to put a 0 and then a 1 in front of the possibilities for 2 bits:
[0, 0, 0]
[0, 0, 1]
[0, 1, 0]
[0, 1, 1]
[1, 0, 0]
[1, 0, 1]
[1, 1, 0]
[1, 1, 1]

Try listing all the possible 16 pairs of 4 bits on your own. Another thing to remember is that a group of n bits can represent 2n values, as we can observe that the number of possible values doubles with each addition of a bit. (more theory on that later)

Sticking to two bits, it appears that adding a bit has increased our storage space to 4 possible states (22).

The natural/conventional mathematical meaning of the bit groupings mentioned above comes from base-2 to base-10 conversions (Details in the previous post):

[0, 0] is 0
[0, 1] is 1
[1, 0] is 2
[1, 1] is 3

However, on top of answering yes/no questions or assigning numbers to these states as shown above, we can also, for example, assign this meaning to our states in an attempt to encode the spelling of “mary” like this:

[0, 0] is m
[0, 1] is a
[1, 0] is r
[1, 1] is y

Using this substitution, we can spell ‘mary’ with groups of two bits from this encoding like:

[0, 0] [0, 1] [1, 0] [1, 1]

And ‘army’ would be encoded like:

[0, 1] [1, 0] [0, 0] [1, 1]

Even more, we could instead assign these meanings to have the two bits store the answer to questions with 4 possible answers. For example, we could describe whether a given colour is red, white, blue, or another colour:

[0, 0] is red
[0, 1] is white
[1, 0] is blue
[1, 1] another colour

By further expanding the storage space to more than two bits, the sky is the limit for how many states you can represent.

For example, when talking about a digital image, one measure of the quality of the image is the colour depth of the image, measured by something called bpp (bits per pixel). That is, as you might have guessed, how many bits of storage are used to represent one pixel in the image. So for a 32-bpp ARGB(more on that later) image, 32 bits for each pixel are used, with 8 bpp used to numerically represent each colour channel (red, green, and blue) and 8 bpp used to numerically describe the degree of transparency for that pixel.

[move to Boolean Logic/functionality/decisions based on bits] Is there anything else we can do with two bits? We said bits are values. We need to introduce a few simple concepts before we can do that fully.

Logical Operators

Operators are rules that bind terms together. Terms are either values or variables. Operators can be unary or binary depending on whether they apply to a single term or are used to combine two terms into a single term. When a unary operator occurs, it takes precedence over any binary operator involving that bit. Just like in mathematics, statements can be chained and parentheses can be used to group operations.

To start, we’ll introduce the unary operator NOT and the two most common binary operators: AND and OR.

AND

The AND operator is a binary operator that combines two bits into one bit and is only 1 when both bits are 1. So: 1 AND 1 is true, every other pair is 0.

Typical use: Evaluating if all requirements out of a list of mandatory requirements are met.

OR

The OR operator is a binary operator that combines two bits into one and is 1 when any of the two bits is 1. So: 0 OR 0 is false, every other pair is 1.

Typical use: Evaluating if any requirement out of a list of possible requirements is met.

NOT

The NOT operator is a unary operator that inverts the state of a bit. In other words, NOT 1 is 0, and NOT 0 is 1.

Typical use: TBD

Variables and Assignment

I promised we’re not focusing on any programming languages in this series, but we do need to develop a pseudo-code language to move things forward.

Let’s define “variable” as something which has a name and can hold a value, like x in mathematics. Also, let’s define the operator “:” as a binary operator between a variable and a value. The rule is:

x:0 

means “x takes/stores the value of 0”. Whenever you mention x after this statement, you can think of it as “getting the value that x has.”

Multiple Bits in Practice, with variables and operators

Operators make it possible for us to find new uses for multiple bits. Let’s say George is trying to get a driver’s license. Then, instead of grouping our bits, we can use multiple “individual” bits to store answers to some questions:

medicalExamPassed: the answer to Did George pass the medical exam?
theoreticalExamPassed: the answer to Did George pass the theoretical exam?
roadTestPassed: the answer to Did George pass the road test?
feesPaid: the answer to Did George pay the required fees?

So finally, by using the AND operator, we can answer the question “Will George receive his license soon?” with:

licenseOnTheWay: medicalExamPassed AND theoreticalExamPassed AND roadTestPassed AND feesPaid

Let’s design a system combining all that we have learned today (bits, variables, assignment and logical operators):

taxesOverdue: the answer to "Is the tax deadline overdue?"
paidTaxes: the answer to "Did George pay his taxes?"
isTaxExempt: the answer to "Is George tax-exempt?"
shouldGeorgeBeWorried: taxesOverdue AND NOT(paidTaxes OR isTaxExempt)

Of course, the possibilities are endless here, and I invite you to think of more examples and uses on your own. I am working on having some interactive parts through the series to facilitate the learning. Meanwhile, text is all we have ?

Hope you enjoyed this session! The next part of our journey will be to look at how groups of bits are used to encode numbers. Until next time!

One thought on “Bits: Beyond Numbers

  1. This in reality is my very first time i go to here. I found so many entertaining stuff in your blog, in particular its argument. In the lots of critical reviews in your writing, I guess I’m not the only 1 acquiring all the leisure here! Keep up the excellent work.

Leave a Reply

Your email address will not be published. Required fields are marked *