chmod 755
- Input
- 111101101₂
- Expected output
- 0o755
Each 3-bit group (111, 101, 101) becomes one octal digit: 7, 5, 5. In hexadecimal the same value would be 0x1ED, grouped 4 bits at a time.
binary to octal
Each octal digit equals exactly 3 binary bits (2³ = 8 possible values): split the number into groups of 3 starting from the least significant bit and swap each group for the matching digit from 0 to 7. That is the same grouping behind Unix permissions like chmod 755.
Each 3-bit group (111, 101, 101) becomes one octal digit: 7, 5, 5. In hexadecimal the same value would be 0x1ED, grouped 4 bits at a time.
Owner gets read plus write (4+2=6), group and others get only read (4): the default permission for files created without execute rights.
The extra leading bit (1) is the sticky bit: on /tmp, it stops one user from deleting files that belong to another user, even with directory write permission.
Converting a number between bases means representing the same value using a different set of digits. A decimal (base 10) number can be expressed exactly in binary (base 2), hexadecimal (base 16), or any other base.
Because one octal digit covers exactly the 8 states of read/write/execute (2³): 3 bits are enough to represent every combination of the 3 permissions without wasting values. A 4-bit group, like in hexadecimal, would have 16 possible states for only 8 real combinations, leaving unused space.
It is the special-bit group, to the left of the 9 rwx bits: setuid is worth 4, setgid is worth 2 and sticky is worth 1, and they can be added together like the regular permissions. chmod 4755 turns on setuid, chmod 2755 turns on setgid, and chmod 1777 turns on only the sticky bit.
Octal is the standard in legacy Unix contexts, such as file permissions and a few system calls; hexadecimal is the standard for memory, CSS colors and network protocols, because 4 bits per digit fit an 8-bit byte more evenly. Outside those two niches, almost every modern system prefers hexadecimal.
All data stays in your browser. No numbers are sent to any server.