# Binary Digits and Bytes

This lesson introduces you to the rules of the binary system and binary to decimal conversions.

## What is a binary digit?

A binary digit, also known as a bit, is the smallest unit used to represent data or information. You can think of a bit as a binary switch. A switch has two states, **ON** and **OFF**. **ON** means that the current is flowing through the switch. **OFF** means that the current is not flowing through the switch, as shown in Figure 1. Likewise, one binary digit can represent two different states, 1 and 0, which correspond to **ON** and **OFF** in a switch, respectively. Alternatively, it can be said that one bit can store one of the two values, 0 or 1.

Bit 1 | Bit 2 | Decimal |
---|---|---|

0 | 0 | 0 |

0 | 1 | 1 |

1 | 0 | 2 |

1 | 1 | 3 |

Table 1: Four configurations using two bits.

To store a bigger value, all you have to do is increase the number of bits. Adding another bit can give you the four configurations in Table 1, which correspond to the decimals 0, 1, 2, and 3. Likewise, three bits can store or represent eight different configurations or eight decimal numbers, ranging from 0 to 7.

If you observe the pattern here, you realize that the number of configurations increases exponentially as a power of 2.

For one bit, there are $2^1 = 2$ total configurations. Similarly, for two bits, there are $2^2 = 4$ total configurations. Hence, it can be deduced that for x-number of bits, the total number of configurations is $2^{x}$. Imagine having a total of at most 10 bits. The amount of numbers they can store or represent is $2^{10}$ = 1024.

## Binary numbers.

Each binary configuration having x-number of bits is called a **binary number** and has a decimal equivalent as shown in Table 1. An example of a $6$-bit binary number is shown in Figure 2. Since it is made up of 6-bits, there are $2^6 = 64$ different configurations possible and therefore, a 6-bit binary number can store 64 different numbers from 0 to 63.

Binary Number Notation:$110101_2$

The right most bit is called the **least significant bit**, and the left most bit is called the **most significant bit**. The first 8 binary numbers are shown in Figure 3.

### Binary to decimal conversion.

To find the decimal equivalent of a binary number, add all the terms that result upon expanding the binary number into a power series with a base of 2 starting with the least significant bit. For example, the binary number $110101_2$ can be expanded in the following way:

$1\times2^{5} + 1\times2^{4} + 0\times2^{3} + 1\times2^{2} + 0\times2^{1}+ 1\times2^{0} = 53$

When a bit is equal to 1, it contributes to the sum during the conversion whereas when it is equal to 0, it does not contribute to the sum. Therefore, just count the powers of 2 that correspond to 1s in the binary number as shown in the example above.

To calculate the number of bits required to represent a decimal number, take the binary logarithm of the decimal number and round the number up. For example, the number of bits required to represent $53$ is equal to $\lceil{log_{2}{53}}\rceil = 6$ bits.

### Binary to decimal converter.

The following is an interactive tool in which you can click on any bit to flip its state. The tool will show you the decimal equivalent of the corresponding binary number.

## What is a byte?

An 8-bit binary number is known as a byte. Or, one byte consists of $8$ bits.

1 byte = 8 bits

An example of a byte is shown in Figure 4. A byte has 256 different configurations which means that a byte can store 256 different numbers. The maximum value that one byte can store is 255, as shown in Figure 5, whereas the minimum value that it can store is 0.

If you want to store a number that is greater than 255, you can add more bytes. Two bytes can store 65536 different configurations, ranging from $0$ to 65535.

## Quiz on binary digits and bytes.

Convert $10_{2}$ from binary to a decimal number and select the right option below:

3

10

2

20