# Binary

The numbers that you are most likely familiar with are the decimal (base-10) system, i.e., the digits 0 through 9. The binary system is a base-2 system that uses only “0s” and “1s” to represent all numbers.

### Example

For example, the **binary** number “100” is the same number as the **decimal** number “4.”

Think about a light bulb, how many ‘states’ can it have? What about 2 Light Bulbs in a row?

- OFF, OFF (0)
- OFF, ON (1)
- ON, OFF (2)
- ON, ON (3)

4 states total! (Counting from 0 to 3)

**Computers use binary** information

The computer converts all of its information into binary before doing computations. Thus, it is important to understand the basics of binary, so we know how to interpret common computer data representations.

In the base-2 system, positional values are denoted as 2^{n}, where n is the position. “n” values begin with 0 and increase from right to left.

### Example:

Base-2 from the 0th power to the 6th power:

Taking into account the base-10 equivalent values gives:

Example

Binary string “1001”:

The decimal equivalent would be: 8+0+0+1 = 9

The binary string shows that there are “1s” at 2^{3} and at 2^{0}, and the “0s” at 2^{2} and 2^{1} indicate that we do not include those numbers in our total. They are significant placeholders, however, and cannot be discarded without changing the value of the string: “11” in binary being equivalent to “3” in decimal.

Example

Converting decimal to binary “26”:

The binary equivalent would be “11010.”

## Bits and Bytes:

Rather than **digits **we refer to the

**bits**(binary digits) of a number. Each binary position represents

**bit**

**(b)**, whether that position is occupied by a “1” or a “0.” An individual bit is typically too small to represent sufficiently larger values. To efficiently process information, computers handle groups of bits. The smallest group of bits processed by a computer is a

**byte (B)**, which is 8 bits long in most modern computers.

Large numbers of bytes are referred to using the International System of Units (SI) prefixes, with those prefixes using a base-2 count rather than the base-10 count. This means that binary-based prefixes do not represent the same amount as base-10 SI prefixes.

Prefix | Standard SI amount | Software amount (Bytes) |
---|---|---|

kilo (k) | 10^{3} = 1,000 | 2^{10} = 1,024 |

mega (M) | 10^{6} = 1,000,000 | 2^{20} = 1024 * 1024 = 1,048,576 |

giga (G) | 10^{9} = 1,000,000,000 | 2^{30} = 1024 * 1024 *1024 = 1,073,741,824 |

tera (T) | 10^{12} = 1,000,000,000,000 | 2^{40} = 1024 * 1024 * 1024 *1024 = 1,099,511,627,776 |

## Example:

How many bits (b) are in a Gigabyte (GB)?

(1024^{3})*8 = 8.6×10^{9} b in 1 GB

#### ASCII

Binary can be converted to the commonly used ASCII codes. ASCII is based on 128 symbols (10 numbers, 26 letters of the English alphabet, some punctuation marks, etc.), and it represents visible characters or commands. The original ASCII table is encoded on 7 bits, and therefore it has 128 characters. Nowadays, ASCII is often extended to 8 bits.

You can type `man ascii`

into a terminal to get a list of the codes. On the Eos machine, you’ll a table with a header like this:

`Oct Dec Hex Char`

with a table. One line is presented from the table here — we see that the hex value of the letter `w`

is `77`

.

`167 119 77 w`

If you use the terminal on your personal machine, you may see a different formatting for the output.