How to convert decimal to octal
- Type decimal numbers into Input, one per line.
- The octal value of each appears in the output as you type.
- Copy the result and add a prefix if your code needs one: 0o in Python and JavaScript, or a leading 0 in C.
Converting decimal to octal by hand
Divide by 8 and note the remainder, then divide the result by 8 again until you reach 0. The remainders read from bottom to top are the octal digits. For 420:
| Division | Result | Remainder |
|---|---|---|
| 420 ÷ 8 | 52 | 4 |
| 52 ÷ 8 | 6 | 4 |
| 6 ÷ 8 | 0 | 6 |
Read upwards, that’s 644. To check, multiply back: 6 × 64 + 4 × 8 + 4 = 420. Every remainder is between 0 and 7, which is why 8 and 9 never appear in octal.
Decimal 0 to 16 in octal
| Decimal | Octal | Decimal | Octal |
|---|---|---|---|
| 0 | 0 | 9 | 11 |
| 1 | 1 | 10 | 12 |
| 2 | 2 | 11 | 13 |
| 3 | 3 | 12 | 14 |
| 4 | 4 | 13 | 15 |
| 5 | 5 | 14 | 16 |
| 6 | 6 | 15 | 17 |
| 7 | 7 | 16 | 20 |
| 8 | 10 |
Octal is rare in new code, but it still turns up in Unix permissions and umask values like 022, and in escape sequences in C strings, where \101 is the character with code 65, a capital A.