Developer Bases

Decimal to octal

Decimal value
Octal 755
Divide by eight, keep the remainders
The same number elsewhere
Decimal 493
Binary 111101101
Binary, grouped 0001 1110 1101
Hexadecimal 1ED
Bits needed 9
Note
Group binary into threes
DecimalBinaryOctalHex
0000
1111
81000108
10101012A
15111117F
16100002010
64100000010040
100110010014464
25511111111377FF
256100000000400100
1024100000000002000400
655351111111111111111177777FFFF
Advertisement
320 × 100

Divide repeatedly by eight and read the remainders backwards. 493 gives 755. Alternatively convert to binary and group the bits into threes from the right: each group is one octal digit.

How to convert decimal to octal

1 Enter the decimal number.
2 Read the octal result, with the binary beside it showing the three-bit groups.
3 For a permission value, read the digits left to right as owner, group, others.
4 Write it as 0o755 rather than 0755 if it is going into Python or JavaScript.

Going via binary is usually faster than dividing by eight. Convert to binary, group the bits into threes from the right, and read each group: the grouping is exact because 8 is 2 cubed. This is the same trick that makes hex easy, with three bits instead of four, and it works for any base that is a power of two.

For permissions the digits line up with the bits directly: 493 is 755, which is 111 101 101: read, write and execute for the owner, read and execute for group and others. A fourth digit in front carries the special bits, 4 for setuid, 2 for setgid and 1 for sticky, which is why /tmp is 1777 and a setgid directory is 2775.

The leading zero is the trap. In C a bare 0755 means octal, and that convention survives in enough places to be dangerous; Python 3 and JavaScript in strict mode both reject 0755 outright and want 0o755. The version that bites hardest is passing a decimal number where octal was expected: chmod given the decimal 755 sets octal 1363, which is the sticky bit plus a permission set nobody intended.

Questions

755, which as Unix permissions is rwxr-xr-x.

Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding