Binary to octal with 3-bit groups
This binary to octal converter turns strings of 0s and 1s into base-8 numbers. Because 8 = 2^3, every three bits map to exactly one octal digit, so the conversion is a simple regrouping rather than a calculation.
The 3-bit table
| Bits | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
|---|---|---|---|---|---|---|---|---|
| Octal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Worked example
Split the bits into threes starting from the right, pad the leftmost group with zeros, then replace each group with its digit.
10110011
→ 10 110 011
→ 010 110 011
→ 2 6 3 = 263
After a binary point, group to the right and pad the last group with zeros. 101.101 is 101 . 101, or 5.5 in octal, and 111101101.1 becomes 755.4.
Reading permission bits
Unix stores read, write and execute permission as three bits for the owner, three for the group and three for everyone else. Converting the nine bits to octal gives the familiar chmod number.
Bits Octal Meaning
111101101 755 rwx r-x r-x
110100101 645 rw- r-- r-x
110100100 644 rw- r-- r--
In each triple the bits are worth 4 (read), 2 (write) and 1 (execute), so 101 means read + execute = 5.
Example output
Input Output
1010 12
11111111 377
100000000 400
101.101 5.5
Input notes
- Spaces, commas and underscores are ignored, so the triples may stay spaced out: 111 101 101 is read as 111101101. The field holds one number at a time.
- A
0bprefix and a minus sign are accepted; other characters are flagged with the invalid digit highlighted. - Long values convert exactly, however many bits they have.
Common mistakes
- Starting the groups at the left. 11111111 grouped as 111 111 11 would suggest 7, 7 and 3, but the correct grouping from the right is 11 111 111, which is 377.
- Padding a fraction on the wrong side. 0.1 in binary becomes 0.100, which is 0.4 in octal, not 0.1.
Octal or hex?
Octal suited early machines with 12-, 24- and 36-bit words, which divide evenly into 3-bit digits. Modern byte-oriented systems prefer hexadecimal, because a byte splits into two 4-bit digits but not into whole 3-bit ones. Use binary to hex for bytes and addresses, and octal for permissions. To reverse this conversion, use octal to binary, or decimal to octal if your value starts in base 10.