# Binary to Octal Converter

## Converting Binary to Octal

Binary is the most basic language of computers. Everything, from simple text to full-length movies can be exepressed using binary. Computers use binary because it is a base 2 numbering system, in which each digit value has a value of one or zero. Thanks to the invention of the transistor, computers can represent binary numbers at an electronics level. Simple operations are implemented on the CPU and use binary values to compute.

Binary numbers are *long*, though. You need at least eight binary digits to represent a single character. This is where octal is useful, as it can represent an 3-digit binary number using a single octal value. This comes in handy when dealing with integers that are multiples of three bits wide. For example, Unix file permissions are represented by 12 bits, making octal a good choice for writing them.

The process of converting from binary to octal using grouping is fairly simple. Each group of three binary digits corresponds to a single octal digit.

- Start with a given binary number, and pad it on the left with zeroes until its length is a multiple of three.
- Split up the binary number, starting from the right, into equally sized three digit chunks.
- Working from the right, convert each group into a single octal character using the table.

### Example

Converting `101111010`_{2}

to octal:

- First chunk:
`010`_{2} = 2_{8}

- Second chunk:
`111`_{2} = 7_{8}

- Third chunk:
`101`_{2} = 5_{8}

Thus, `101111010`_{2} = 572_{8}

### Conversion Table

Binary | Oct |
---|

000 | 0 |

001 | 1 |

010 | 2 |

011 | 3 |

100 | 4 |

101 | 5 |

110 | 6 |

111 | 7 |