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!

Bits: Numbers as Bits (Part I)

If you think dogs can’t count, try putting three dog biscuits in your pocket and then giving Fido only two of them.

Phil Pastoret

In mathematics, a base or radix is the number of different digits that a system of counting uses to represent numbers.  the most common base used today is the decimal system. Because “dec” means 10, it uses the 10 digits from 0 to 9.

Wikipedia

As promised, we’re taking a step back from the historical approach for now. Our journey continues with some context which will make it easier to work with and reason about bits and binary numbers.

There is a lot of information online covering numerical bases and their properties. Here, we will focus on demystifying the basics by presenting them in a more straightforward language.

What is a Bit?

The bit is a basic unit of information in computing and digital communications. The name is a portmanteau of binary digit.[1] The bit represents a logical state with one of two possible values. These values are most commonly represented as either “1”or”0″, but other representations such as true/falseyes/no+/, or on/off are common.

https://en.wikipedia.org/wiki/Bit

A bit is functionally a two-state switch. Think of an ordinary “mechanical” one-button lightswitch. Just the lightswitch, not tied to anything else. It can only have two states, which you can observe visually: up or down, pushed or not pushed, etc. A bit is a lot like that: it can hold either a value of 0 or a value of 1.

Of course, you can assign more meaning to a bit than just 0 and 1, and we will discuss this possibility in one of our next posts. In this article, we will look at 0 and 1 as numbers.

What is Counting?

Counting is the process of determining the number of elements of a finite set of objects. The traditional way of counting consists of continually increasing a (mental or spoken) counter by a unit for every element of the set, in some order, while marking (or displacing) those elements to avoid visiting the same element more than once, until no unmarked elements are left; if the counter was set to one after the first object, the value after visiting the final object gives the desired number of elements. 

https://en.wikipedia.org/wiki/Counting

Everyone is familiar with counting. It’s part of our everyday lives. However, much of this happens automatically through memorized patterns, so we’re not usually aware of the details of what is going on when we count.

I find the above-mentioned definition, while correct, possibly confusing to some people. What is counting? Just count, use numbers.

In layman’s terms, you start with a pile of things that you need to count, and start moving them to another pile. As you do that, you use a mental or physical counting board/abacus to keep track of how many objects you have moved so far.

Hypothetically, if you had an abacus with a single column, with the same number of beads as the objects you are trying to count, then that single column would be enough to “physically count”, without putting names to numbers. But (natural) numbers, though countable, are infinite. So we need to reason about them in more abstract ways.

As a practical totally fabricated example, let’s say you are an ancient-times merchant and you own a single column, ten-bead abacus, and each week you know you have to receive ten animal skins as part of a trade agreement. With little instruction, you’d for sure be able to know whether there are ten animal skins in a pile or to take ten animal skins from a pile using this method, never knowing about numbers.

When the number that you need to count increases, it becomes impractical to use that single column method. How would you come up with the number if there were, say 3000 beads on the single-column without recounting? How would you deal with interruptions?.

Assigning a name or symbol for that quantity also becomes paramount. That’s where numerical systems, or thinking of quantities as “piles of piles” come into play (more on that below). In a sense, numerical systems are there to help us communicate by naming quantities.

There are some … who think that the number of the sand is infinite in multitude … again there are some who, without regarding it as infinite, yet think that no number has been named which is great enough to exceed its multitude … But I will try to show you [numbers that] exceed not only the number of the mass of sand equal in magnitude to the earth … but also that of a mass equal in magnitude to the universe.

Archimedes, 3rd century B.C., The Sand-Reckoner

Archimedes made a surprisingly accurate prediction for the number of m grains of sand that would fit in the universe in his writing The Sand-Reckoner. And this approximation was fueled by trying to name some “mass equal in magnitude to the universe”. He needed to know what the universe’s “mass” would be, to exceed it Even as far back as the 3rd century B.C. naming big quantities was important, and to this day mathematicians fight about who can name the biggest number.

Counting in Base 10 (Decimal Base)

Let’s take a trip down memory lane to refresh our memories and break down the counting process into its integral parts.

  • We count in piles of 10, even if we don’t always think about it. An example of these piles are the columns of the counting board below;
  • Our piles each represent a digit from 0 up to 9;
  • The pile on the left of another pile “stands for” an amount 10 times bigger. In other words, in our counting board below, the rightmost column stands for digits, the middle column stands for tens and the leftmost column stands for hundreds;
  • The thought process for going beyond 9 within any pile while counting is: “I have reached the maximum amount I can make in this pile. I need to start a new pile here and add one to the pile on the left”; If the pile on the left had also reached its maximum, we apply the same rule to that pile, and so on;
  • In reality, we don’t have a hard limitation on the number of digits; we can always add one more pile to the left, following the same rule.

You can use the numerical input box to play around with the board see these concepts in action:

A few observations about the board:

  • There are three columns on the board, each one representing a digit. Thus, the board can represent numbers from 0 to 999.
  • Columns each have 9 beads that can be moved around to represent a digit. In other words, we have a "name" for each of the ten states of a column;

Counting in Base 2 (Binary Base)

What about counting in binary? Let's copy-paste our rules from the previous section and adapt them to having only 0 and 1 as digits. You can adapt these rules, in a similar fashion and apply them to any other base of your choosing.

  • We count in piles of 10 2, even if we don't always think about it. It will get some getting used to. An example of these piles are the columns of the counting board below;
  • Our piles each represent digits from 0 up to 9 1;
  • The pile on the left of another pile "stands for" an amount 10 2 times bigger. In other words, in our counting board below, the rightmost column stands for digits, the middle column stands for tens twos and the leftmost column stands for hundreds fours;
  • The thought process for going beyond 9 1 within any pile while counting is: "I have reached the maximum amount I can make in this pile. I need to start a new pile here and add one to the pile on the left"; If the pile on the left had also reached its maximum, we apply the same rule to that pile, and so on;
  • In reality, we don't have a hard limitation on the number of digits; we can always add one more pile to the left, following the same rule.

You can use the numerical input box to play around with the board see these concepts in action:

A few observations about the board:

  • There are three columns on the board, each one representing a binary digit. Thus, the board can represent numbers from 0 to 111 (in binary). corresponding to 0 to 7 (in decimal);
  • Columns each have 9 1 beads that can be moved around to represent a digit. In other words, we have a "name" for each of the ten two states of a column;

So how do we know that 7 is the largest number with 3 binary digits? Well, we know the maximum for each column is 1. We also know that the columns' values per unit are 4, 2, and 1, respectively. Remember that each time we "move left" through the "binary" piles the column's value per unit doubles. Adding 4 * 1 , 2 * 1 , and 1 * 1, we get 7.

We'll cover this in more detail in the next post when we will cover base conversions. Afterward, we will dive deeper into the particularities of bits and the binary numerical system.

I hope you've enjoyed this small math reminder on numerical bases, and I hope to see you next time!