Octal to decimal converter
This octal to decimal converter turns base-8 numbers into ordinary base-10 values. You will need it when a program, API or config format wants a file mode as a plain integer, or when you meet octal constants in older code.
Place values in base 8
From the right, octal places are worth 1, 8, 64, 512 and 4096. Multiply each digit by its place value and add up the results.
755 = 7 × 64 + 5 × 8 + 5 × 1
= 448 + 40 + 5
= 493
After an octal point, places are worth 1/8, 1/64 and so on. 17.4 is 8 + 7 + 4/8 = 15.5, and 0.1 in octal is exactly 0.125.
Example
Input Output
12 10
377 255
644 420
755 493
0o777 511
17.4 15.5
Why convert permissions to decimal?
JSON has no octal numbers, and several libraries take a file mode as a normal integer. If you write 755 where octal is expected but decimal is read, you get a very different mode. Converting first avoids that: chmod 644 is 420, 755 is 493 and 777 is 511.
The reverse trap exists in C, where a leading zero makes a literal octal. 0755 in C is 493, while 755 is seven hundred fifty-five. Python 3 refuses the ambiguous form and requires 0o755, and JavaScript's parseInt("0755") returns 755 because it reads the string as decimal.
Input rules
- Only digits 0–7 are valid. An 8 or 9 means the value was not octal, and the tool reports an error naming it.
- A
0oprefix and leading zeros are fine: 0755, 755 and 0o755 all give 493. - Spaces and underscores are ignored, the field holds one number at a time, and integers of any size convert exactly.
Quick reference
A few values come up again and again: octal 10 is 8, 100 is 64, 1000 is 512 and 2000 is 1024. The common umask 022 is 18 in decimal, and applying it to 0777 clears the group and other write bits, leaving the default directory mode 755, or 493.
Where octal still turns up
Octal has mostly given way to hexadecimal, but it survives in a few places where you may need the decimal value:
- Escape sequences.
\033[31mstarts red text in a terminal. Octal 33 is decimal 27, the Escape character, the same byte as\x1b. - tar archives. The classic tar header stores file size, mode and modification time as octal text. A size field of
00000001750means 1,000 bytes. oddumps. The Unixodcommand prints octal by default, so its offsets and byte values need converting before they match other tools.- Aircraft transponder codes. Squawk codes use only the digits 0 to 7, which is why there are 4,096 of them rather than 10,000. The emergency code 7700 is 4032 in decimal.
Related tools
Use decimal to octal to go back. To see which permission bits a mode sets, octal to binary expands every digit into its read, write and execute bits, and the all number converter gives the value in several bases at once.
Convert octal to decimal in Python
In Python, int("755", 8) converts an octal string to decimal, and the string may carry the 0o prefix. For a value written directly in source code, use an octal literal such as 0o755; oct() goes the other way. What catches people is dropping the prefix. A bare 755 is the decimal number seven hundred fifty-five, so os.chmod(path, 755) passes a mode that is 1363 in octal, not the rwxr-xr-x that was intended.
print(int("755", 8)) # 493
print(int("0o17", 8)) # 15, the 0o prefix is accepted
print(0o755) # 493, an octal literal in source code
print(oct(493)) # 0o755, decimal back to octal
# The classic slip: 755 without the prefix is a decimal number
print(oct(755)) # 0o1363, the mode os.chmod(path, 755) would set
Paste a list of octal values into the converter above to confirm what your script should print, or use the chmod calculator when the number is a file permission.