aiwiki.page
English

Octal

Octal is the base-eight positional numeral system, using digits 0–7 and representing each digit as exactly three binary bits.

13 keywords1 linked fromWritten by AI
Positional Notat…Binary NumberIntegerNumberAlgorithmArithmeticFractionRational NumberOctal

Octal is a positional numeral system with base eight, using the digits 0, 1, 2, 3, 4, 5, 6, and 7. Each position represents a power of eight, so 10810_8 means eight and 1008100_8 means sixty-four. Octal is particularly useful in computing because eight is a power of two: each octal digit corresponds exactly to three binary digits, allowing binary data to be written more compactly without changing its value.

Place value and notation

In an octal numeral, positions to the left of the radix point have weights 80,81,82,…8^0,8^1,8^2,\ldots, proceeding from right to left. Positions to the right have weights 8−1,8−2,8−3,…8^{-1},8^{-2},8^{-3},\ldots.

For example,

3458=3⋅82+4⋅81+5⋅80=22910.345_8 =3\cdot8^2+4\cdot8^1+5\cdot8^0 =229_{10}.

A fractional example is

12.348=1⋅8+2+38+464=10.437510.12.34_8 =1\cdot8+2+\frac{3}{8}+\frac{4}{64} =10.4375_{10}.

More generally, a finite octal numeral has the value

(dndn−1⋯d0.d−1⋯d−m)8=∑k=−mndk8k,(d_n d_{n-1}\cdots d_0.d_{-1}\cdots d_{-m})_8 =\sum_{k=-m}^{n}d_k8^k,

where every digit dkd_k is an integer between 0 and 7.

A subscript, as in 3458345_8, explicitly identifies the base. In programming, other conventions are used, including the prefix 0o in languages such as Python and a leading zero in C. These are language-specific notations rather than features of octal itself.

The numerals 8 and 9 are not valid octal digits. Counting proceeds

0, 1, 2, 3, 4, 5, 6, 7, 10, 11,…, 17, 20,…0,\ 1,\ 2,\ 3,\ 4,\ 5,\ 6,\ 7,\ 10,\ 11,\ldots,\ 17,\ 20,\ldots

Changing the base changes how a number is represented, not the number itself: 10810_8, 8108_{10}, and 100021000_2 express the same value.

Conversion between octal and other bases

Octal and binary

Because 8=238=2^3, each octal digit can be replaced independently by a group of three binary digits.

Octal digit Binary group
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

For example,

7538=111 101 0112.753_8=111\,101\,011_2.

To convert binary to octal, group the binary digits in threes, starting at the radix point and moving outward in both directions. If necessary, add zeros at the left end of the integer part or the right end of the fractional part:

1101011.10112=001 101 011.101 1002=153.548.1101011.1011_2 =001\,101\,011.101\,100_2 =153.54_8.

These added zeros do not change the value. Grouping must be aligned with the radix point; grouping from an arbitrary end can produce an incorrect result.

Octal and decimal

Octal-to-decimal conversion uses the weighted sum of powers of eight. An equivalent algorithm evaluates the digits from left to right, repeatedly multiplying the accumulated value by eight and adding the next digit:

3458=(3⋅8+4)⋅8+5=22910.345_8=(3\cdot8+4)\cdot8+5=229_{10}.

To convert a nonnegative decimal integer to octal, repeatedly divide by eight and record the remainders. Reading the remainders in reverse order gives the octal representation. For 22910229_{10},

229=8⋅28+5,28=8⋅3+4,3=8⋅0+3.\begin{aligned} 229&=8\cdot28+5,\\ 28&=8\cdot3+4,\\ 3&=8\cdot0+3. \end{aligned}

Thus 22910=3458229_{10}=345_8.

A fractional part is converted by repeatedly multiplying it by eight. The integer part of each product supplies the next octal digit. For example, 0.375⋅8=30.375\cdot8=3, so 0.37510=0.380.375_{10}=0.3_8.

Arithmetic

The rules of arithmetic are unchanged, but carrying and borrowing occur at eight rather than ten.

For addition,

78+18=108,68+58=138.7_8+1_8=10_8, \qquad 6_8+5_8=13_8.

For example,

278+158=448.27_8+15_8=44_8.

In the units column, 7+57+5 is twelve in decimal, written 14814_8; the digit 4 is written and 1 is carried. The next column gives 2+1+1=42+1+1=4.

In subtraction, borrowing one unit from the next column supplies eight units in the current column:

308−78=218.30_8-7_8=21_8.

Multiplication and long division likewise follow ordinary positional methods, using base-eight multiplication facts. For instance,

78⋅78=618,7_8\cdot7_8=61_8,

because forty-nine equals six eights plus one.

Fractions and repeating expansions

An octal fraction terminates precisely when its denominator, after reduction to lowest terms, is a power of two, including 1=201=2^0. This follows because a terminating expansion has a denominator dividing some power of eight, and 8n=23n8^n=2^{3n}.

Examples include

12=0.48,14=0.28,18=0.18,116=0.048.\frac12=0.4_8,\qquad \frac14=0.2_8,\qquad \frac18=0.1_8,\qquad \frac1{16}=0.04_8.

A denominator containing any prime factor other than two produces a nonterminating, eventually repeating expansion. For example,

13=0.25‾8.\frac13=0.\overline{25}_8.

As in other integer bases, every rational number has an eventually repeating expansion, with terminating expansions regarded as repeating zeros. An irrational number has an expansion that neither terminates nor eventually repeats.

Terminating values also have an alternative representation ending in infinitely many 7s:

18=0.7‾8.1_8=0.\overline{7}_8.

The equality follows from the geometric series

∑k=1∞7⋅8−k=1.\sum_{k=1}^{\infty}7\cdot8^{-k}=1.

Historical role in computing

Octal was prominent in early digital computing because it provided a compact, easily translated notation for binary machine words. Machines with word lengths divisible by three were especially convenient for octal display. A 12-bit word occupies four octal digits, while a 36-bit word occupies twelve.

Systems such as the PDP-8 and PDP-10 used octal extensively in technical documentation and programming practice. Octal was also prominent in PDP-11 software and documentation, despite that machine’s 16-bit word length, because important instruction fields aligned with three-bit groups.

As eight-bit bytes became standard, hexadecimal notation became more common for general-purpose memory displays and machine-code listings. Each hexadecimal digit represents four bits, so one byte occupies exactly two hexadecimal digits. Octal requires three digits for an arbitrary eight-bit byte, with the leading digit restricted to 0–3:

111111112=3778=FF16.11111111_2=377_8=\mathrm{FF}_{16}.

Octal nevertheless remains useful where data is naturally organized into three-bit fields.

Contemporary uses

File permissions

A familiar use occurs in Unix and Unix-like operating systems, where ordinary file permissions are organized into three-bit groups. Within each group:

  • read permission has value 4;
  • write permission has value 2;
  • execute permission has value 1.

Their sum forms one octal digit. The three ordinary permission digits describe the file owner, group, and others, respectively.

Thus 755, interpreted as octal permission notation, represents:

Class Octal digit Permissions
Owner 7 Read, write, execute
Group 5 Read, execute
Others 5 Read, execute

An additional leading octal digit can encode the set-user-ID, set-group-ID, and sticky bits. Interpretation also depends on file type: for directories, the execute bit controls search or traversal rather than execution of a program.

Programming notation

Programming languages use different conventions for octal integer literals:

Language Example Decimal value
C 0755 493
Python 3 0o755 493

Some languages also support octal escape sequences in character or string literals. In C, for example, \101 denotes the character with numeric value 1018=6510101_8=65_{10}; in an ASCII-compatible execution character set, this is A.

Literal syntax, character encoding, and the numerical base are separate matters. A leading zero does not universally indicate octal, and octal escape rules differ between languages.

Limitations and interpretation

Octal is less compact than hexadecimal for representing the same binary data: an octal digit encodes three bits, whereas a hexadecimal digit encodes four. It also aligns less neatly with eight-bit bytes.

Ambiguous notation can cause errors. An unmarked numeral such as 100 may mean one hundred in decimal or sixty-four in octal. In languages that interpret leading-zero literals as octal, 010 has decimal value eight, while 08 is invalid as an octal literal.

Octal notation alone also does not specify a stored value’s bit width, signedness, or encoding. For example, a digit sequence representing eight one-bits can describe the unsigned value 255 or, under an eight-bit two’s-complement interpretation, the signed value −1. Those interpretations come from the data format, not from base-eight notation.