Bits and Binaries

A bit is a discrete variable that can only take two possible values, for example, 0 and 1 (or any other two distinct numbers). It can also be the truth value of a logical statement because it will always be either true or false.

Any information can be encoded as a string of bits. For instance, if you wanted to express the colors of the rainbow, you would need three bits. This is because, with three bits, you can make $2^3=8$ distinct strings, to which you then assign a color (you would be left with one spare string).

Color Binary string The outcome of a dice
red 000 1
orange 001 2
yellow 010 3
green 011 4
blue 100 5
purple 101 6

<aside> 💡 If we used the outcome of a rolled dice to encode the same information, we would need only one dice instead of three bits. This is clearly more efficient, but you will soon learn why it is much more convenient for computers to use bits.

</aside>

A practical example of encoding information in bits is the binary number system. As opposed to the decimal system in which you denote how many times each power of ten is in a number, the binary system represents (by two distinct numerals) which powers of two make up a number.

$$ \begin{aligned}3208_{10}&=3(10^3)+2(10^2)+0(10^1)+8(10^0)\\ &=3(1000)+2(100)+0(10)+8(1)\\ &=3208\\ \\1101_2&=1(2^3)+1(2^2)+0(2^1)+1(2^0)\\&=8+4+1\\&=13

\end{aligned} $$

Single-bit gates

To perform some operations with encoded information, we need logic gates. A logic gate takes a certain number of bits as an input, depending on which it gives at least one output. The simplest gates have one input and one output, for which four possibilities exist.

Identity gate

Writing down the truth table for the identity gate is effortless because it does not change the bits in any way. This gate is used to amplify weak signals and to introduce a pause for certain parts of operations, which is also why it is sometimes called the buffer gate.

Input A Output A
0 0
1 1

Symbol of the identity gate

Symbol of the identity gate

NOT gate

The NOT gate turns a 0 into a 1 and vice versa.

Input A Output AÌ…
0 1
1 0

Symbol of the NOT gate

Symbol of the NOT gate

The other two gates, one of which always gives 0 and the other always gives 1, notwithstanding the input, are not that commonly used.

Two-bit gates

Two-bit gates take two bits as input and give one as output. There are a total of sixteen possible gates, but only a few are commonly used.

AND gate