Octal Number System
Comprendere Base-8
Impara Informazioni OctalOctal (base-8) bridges binary e human readability. While hexadecimal ha largely replaced it in modern computing, octal remains important in Unix file permissions e some programming contexts. Comprendere octal provides insight into number system design e computer history.
How Octal Works
Positional Values
Each position e un power di 8:
- ...512, 64, 8, 1 (8³, 8², 8¹, 8⁰)
Esempio: 752 (octal)
- 7 × 64 = 448
- 5 × 8 = 40
- 2 × 1 = 2
- Total = 490 (decimal)
Perche Only 0-7?
Quando you reach 8, you carry un il next position:
- Decimal 7 = 7 octal
- Decimal 8 = 10 octal
- Decimal 9 = 11 octal
Octal-Decimal Comparison
| Decimal | Octal | Binary |
|---|---|---|
| 0 | 0 | 000 |
| 5 | 5 | 101 |
| 7 | 7 | 111 |
| 8 | 10 | 1000 |
| 10 | 12 | 1010 |
| 16 | 20 | 10000 |
| 64 | 100 | 1000000 |
| 100 | 144 | 1100100 |
| 255 | 377 | 11111111 |
| 512 | 1000 | 1000000000 |
Octal e Binary
Il key relationship: each octal digit equivale un esattamente 3 binary digits.
Octal un Binary
Converti each digit un 3 bits:
- 0 = 000, 1 = 001, 2 = 010, 3 = 011
- 4 = 100, 5 = 101, 6 = 110, 7 = 111
Esempio: 752 (octal) un binary
- 7 = 111
- 5 = 101
- 2 = 010
- Risultato: 111101010
Binary un Octal
Group bits in threes da il right:
- 111101010 → 111 | 101 | 010 → 7 5 2
Octal in Unix File Permissions
Il most common modern usare di octal e Unix/Linux file permissions.
Permission Bits
- r (read): 4
- w (write): 2
- x (execute): 1
Three Categories
- Owner: First digit
- Group: Secondo digit
- Others: Third digit
Comuni Permissions
| Octal | Meaning | Symbol |
|---|---|---|
| 755 | Owner: all, Others: read+execute | rwxr-xr-x |
| 644 | Owner: read+write, Others: read | rw-r--r-- |
| 777 | Everyone: all permissions | rwxrwxrwx |
| 600 | Owner: read+write only | rw------- |
Storia: Perche Octal?
Early Computing
- Some early computers used 12, 24, o 36-bit words
- These divide evenly da 3
- Octal provided clean representation
- PDP-8 (12-bit) e PDP-10 (36-bit) used octal extensively
Il Shift un Hexadecimal
- 8-bit byte became standard (IBM 360)
- 8 bits = 2 hex digits (perfect fit)
- 8 bits = 2.67 octal digits (awkward)
- Hex won per most purposes
Octal in Programming
Notation
- C/C++/JavaScript: Leading 0 (dangerous!)
- Python 3: 0o prefix (clear)
- Some languages: 0o o @
Il Danger di Leading Zeros
In C e JavaScript:
010= 8 (octal!), not 100777= 511 (often per permissions)
This causes bugs quando people accidentally write 010 expecting decimal 10.
Modern Practice
- Python 3 requires explicit 0o prefix
- Many style guides discourage implicit octal
- Octal literals mainly used per file permissions
Convertendo Decimal un Octal
Method: Repeated Division da 8
- Divide da 8, record remainder
- Divide quotient da 8, record remainder
- Repeat until quotient e 0
- Read remainders bottom-un-top
Esempio: 500 (decimal) un octal
| Division | Quotient | Remainder |
|---|---|---|
| 500 ÷ 8 | 62 | 4 |
| 62 ÷ 8 | 7 | 6 |
| 7 ÷ 8 | 0 | 7 |
Risultato: 764 (octal)
Conclusione
Octal (base-8) era historically important in computing quando word sizes erano multiples di 3 bits. While hexadecimal ha largely replaced it per general usare, octal remains essential per Unix file permissions e occasionally appears in legacy systems. Il key insight e that each octal digit represents esattamente 3 binary bits, making conversione straightforward. Comprendere octal helps quando working con Unix systems, reading legacy code, o studying computer history.