Octal is anumeral system for representing a numeric value asbase 8. Generally, an octal digit is represented as "0" to "7" with the same value as fordecimal but with each place a power of 8. For example:
In decimal, each place is apower of ten. For example:
An octal digit can represent the value of a 3-digitbinary number (starting from the right). For example, the binary representation for decimal 74 is 1001010. Two zeroes can be added at the left:(00)1 001 010, corresponding to the octal digits1 1 2, yielding the octal representation 112.
TheYuki language inCalifornia has an octal system because the speakers count using the spaces between their fingers rather than the fingers themselves.[2]
ThePamean languages inMexico also have an octal system, because some of their speakers "count the knuckles of the closed fist for each hand (excluding the thumb), so that two hands equals eight."[3]
It has been suggested that the reconstructedProto-Indo-European (PIE) word for "nine" might be related to the PIE word for "new". Based on this, some have speculated that proto-Indo-Europeans used an octal number system, though the evidence supporting this is slim.[4]
In 1716, KingCharles XII of Sweden askedEmanuel Swedenborg to elaborate a number system based on 64 instead of 10. Swedenborg argued, however, that for people with less intelligence than the king such a big base would be too difficult and instead proposed 8 as the base. In 1718 Swedenborg wrote (but did not publish) a manuscript: "En ny rekenkonst som om vexlas wid Thalet 8 i stelle then wanliga wid Thalet 10" ("A new arithmetic (or art of counting) which changes at the Number 8 instead of the usual at the Number 10"). The numbers 1–7 are there denoted by the consonants l, s, n, m, t, f, u (v) and zero by the vowel o. Thus 8 = "lo", 16 = "so", 24 = "no", 64 = "loo", 512 = "looo" etc. Numbers with consecutive consonants are pronounced with vowel sounds between in accordance with a special rule.[6]
Writing under the pseudonym "Hirossa Ap-Iccim" inThe Gentleman's Magazine, (London) July 1745,Hugh Jones proposed an octal system for British coins, weights and measures. "Whereas reason and convenience indicate to us an uniform standard for all quantities; which I shall call theGeorgian standard; and that is only to divide every integer in eachspecies into eight equal parts, and every part again into 8 real or imaginary particles, as far as is necessary. For tho' all nations count universally bytens (originally occasioned by the number of digits on both hands) yet 8 is a far more complete and commodious number; since it is divisible into halves, quarters, and half quarters (or units) without a fraction, of which subdivisionten is uncapable...." In a later treatise onOctave computation (1753) Jones concluded: "Arithmetic byOctaves seems most agreeable to the Nature of Things, and therefore may be called Natural Arithmetic in Opposition to that now in Use, by Decades; which may be esteemed Artificial Arithmetic."[7]
In 1801,James Anderson criticized the French for basing themetric system on decimal arithmetic. He suggested base 8, for which he coined the termoctal. His work was intended as recreational mathematics, but he suggested a purely octal system of weights and measures and observed that the existing system ofEnglish units was already, to a remarkable extent, an octal system.[8]
In the mid-19th century, Alfred B. Taylor concluded that "Our octonary [base 8]radix is, therefore, beyond all comparison the "best possible one" for an arithmetical system." The proposal included a graphical notation for the digits and new names for the numbers, suggesting that we should count "un,du,the,fo,pa,se,ki,unty,unty-un,unty-du" and so on, with successive multiples of eight named "unty,duty,thety,foty,paty,sety,kity andunder." So, for example, the number 65 (101 in octal) would be spoken in octonary asunder-un.[9][10] Taylor also republished some of Swedenborg's work on octal as an appendix to the above-cited publications.
Octal became widely used in computing when systems such as theUNIVAC 1050,PDP-8,ICL 1900 andIBM mainframes employed6-bit,12-bit,24-bit or36-bit words. Octal was an ideal abbreviation of binary for these machines because their word size is divisible by three (each octal digit represents three binary digits). So two, four, eight or twelve digits could concisely display an entiremachine word. It also cut costs by allowingNixie tubes,seven-segment displays, andcalculators to be used for the operator consoles, where binary displays were too complex to use, decimal displays needed complex hardware to convert radices, andhexadecimal displays needed to display more numerals.
All modern computing platforms, however, use 16-, 32-, or 64-bit words, further divided intoeight-bit bytes. On such systems three octal digits per byte would be required, with the most significant octal digit representing two binary digits (plus one bit of the next significant byte, if any). Octal representation of a 16-bit word requires 6 digits, but the most significant octal digit represents (quite inelegantly) only one bit (0 or 1). This representation offers no way to easily read the most significant byte, because it is smeared over four octal digits. Therefore, hexadecimal is more commonly used in programming languages today, since two hexadecimal digits exactly specify one byte. Some platforms with a power-of-two word size still have instruction subwords that are more easily understood if displayed in octal; this includes thePDP-11 andMotorola 68000 family. The modern-day ubiquitousx86 architecture belongs to this category as well, but octal is rarely used on this platform, although certain properties of the binary encoding of opcodes become more readily apparent when displayed in octal, e.g. the ModRM byte, which is divided into fields of 2, 3, and 3 bits, so octal can be useful in describing these encodings. Before the availability ofassemblers, some programmers would handcode programs in octal; for instance, Dick Whipple and John Arnold wroteTiny BASIC Extended directly in machine code, using octal.[11]
Octal is sometimes used in computing instead of hexadecimal, perhaps most often in modern times in conjunction withfile permissions underUnix systems (seechmod). It has the advantage of not requiring any extra symbols as digits (the hexadecimal system is base-16 and therefore needs six additional symbols beyond 0–9).
For example, the literal 73 (base 8) might be represented as073,o73,q73,0o73,\73,@73,&73,$73 or73o in various languages.
Newer languages have been abandoning the prefix0, as decimal numbers are often represented with leading zeroes. The prefixq was introduced to avoid the prefixo being mistaken for a zero, while the prefix0o was introduced to avoid starting a numerical literal with an alphabetic character (likeo orq), since these might cause the literal to be confused with a variable name. The prefix0o also follows the model set by the prefix0x used for hexadecimal literals in theC language; it is supported byHaskell,[19]OCaml,[20]Python as of version 3.0,[21]Raku,[22]Ruby,[23]Tcl as of version 9,[24]PHP as of version 8.1,[25]Rust[26] andECMAScript as of ECMAScript 6[27] (the prefix0 originally stood for base 8 inJavaScript but could cause confusion,[28] therefore it has been discouraged in ECMAScript 3 and dropped in ECMAScript 5[29]).
Octal numbers that are used in some programming languages (C,Perl,PostScript...) for textual/graphical representations of byte strings when some byte values (unrepresented in a code page, non-graphical, having special meaning in current context or otherwise undesired) have to be toescaped as\nnn. Octal representation may be particularly handy with non-ASCII bytes ofUTF-8, which encodes groups of 6 bits, and where any start byte has octal value\3nn and any continuation byte has octal value\2nn.
Transponders in aircraft transmit a "squawk"code, expressed as a four-octal-digit number, when interrogated by ground radar. This code is used to distinguish different aircraft on the radar screen.
To convert an integer written in decimal to octal,divide the original number by the largest possible power of 8 and divide the remainders by successively smaller powers of 8 until the power is 1. The octal representation is formed by the quotients, written in the order generated by the algorithm.For example, to convert 12510 to octal:
To convert a decimal fraction to octal, multiply by 8; the integer part of the result is the first digit of the octal fraction. Repeat the process with the fractional part of the result, until it is null or within acceptable error bounds.
Example: Convert 0.1640625 to octal:
0.1640625 × 8 = 1.3125 =1 + 0.3125
0.3125 × 8 = 2.5 =2 + 0.5
0.5 × 8 = 4.0 =4 + 0
Therefore, 0.164062510 = 0.1248.
These two methods can be combined to handle decimal numbers with both integer and fractional parts, using the first on the integer part and the second on the fractional part.
To convert an integer written in decimal to octal, prefix the number with "0.". Perform the following steps for as long as digits remain on the right side of the radix:Double the value to the left side of the radix, usingoctal rules, move the radix point one digit rightward, and then place the doubled value underneath the current value so that the radix points align. If the moved radix point crosses over a digit that is 8 or 9, convert it to 0 or 1 and add the carry to the next leftward digit of the current value.Addoctally those digits to the left of the radix and simply drop down those digits to the right, without modification.
To convert octals to decimals, prefix the number with "0.". Perform the following steps for as long as digits remain on the right side of the radix: Double the value to the left side of the radix, usingdecimal rules, move the radix point one digit rightward, and then place the doubled value underneath the current value so that the radix points align.Subtractdecimally those digits to the left of the radix and simply drop down those digits to the right, without modification.
The process is the reverse of the previous algorithm. The binary digits are grouped by threes, starting from the least significant bit and proceeding to the left and to the right. Add leading zeroes (or trailing zeroes to the right of decimal point) to fill out the last group of three if necessary. Then replace each trio with the equivalent octal digit.
The conversion is made in two steps using binary as an intermediate base. Octal is converted to binary and then binary to hexadecimal, grouping digits by fours, which correspond each to a hexadecimal digit.
Hexadecimal to octal conversion proceeds by first converting the hexadecimal digits to 4-bit binary values, then regrouping the binary bits into 3-bit octal digits.
Due to having only factors of two, many octal fractions have repeating digits, although these tend to be fairly simple:
Decimal base Prime factors of the base:2,5 Prime factors of one below the base:3 Prime factors of one above the base:11 Other Prime factors:7 13 17 19 23 29 31
Octal base Prime factors of the base:2 Prime factors of one below the base:7 Prime factors of one above the base:3 Other Prime factors:5 13 15 21 23 27 35 37
^Alfred B. Taylor,Report on Weights and Measures, Pharmaceutical Association, 8th Annual Session, Boston, 1859-09-15. See pages 48 and 53.
^Alfred B. Taylor, Octonary numeration and its application to a system of weights and measures,Proc. Amer. Phil. Soc. Vol XXIVArchived 2023-04-01 at theWayback Machine, Philadelphia, 1887; pages 296-366. See pages 327 and 330.
^Paul, Matthias R. (1997-07-30)."NWDOS-TIPs — Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds".MPDOSTIP. Release 157 (in German) (3 ed.).Archived from the original on 2016-11-04. Retrieved2014-08-06. (NB. NWDOSTIP.TXT is a comprehensive work onNovell DOS 7 andOpenDOS 7.01, including the description of many undocumented features and internals. It is part of the author's yet largerMPDOSTIP.ZIP collection maintained up to 2001 and distributed on many sites at the time. The provided link points to a HTML-converted older version of theNWDOSTIP.TXT file.)
^Paul, Matthias R. (2002-03-26)."Updated CLS posted". freedos-dev mailing list.Archived from the original on 2019-04-27. Retrieved2014-08-06.
^CCI Multiuser DOS 7.22 GOLD Online Documentation.Concurrent Controls, Inc. (CCI). 1997-02-10. HELP.HLP.
^"parseInt()",Mozilla Developer Network (MDN),archived from the original on 2014-03-05, retrieved2014-01-03,If the input string begins with "0" (a zero), radix is assumed to be 8 (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 clarifies that 10 (decimal) should be used, but not all browsers support this yet