In mathematics and digital electronics , a binary number is a number expressed in the base-2 numeral system or binary numeral system , which uses only two symbols: The base-2 numeral system is a positional notation with a radix of 2. Each digit is referred to as a bit. Because of its straightforward implementation in digital electronic circuitry using logic gates , the binary system is used by almost all modern computers and computer-based devices.
The modern binary number system was studied in Europe in the 16th and 17th centuries by Thomas Harriot , Juan Caramuel y Lobkowitz , and Gottfried Leibniz. However, systems related to binary numbers have appeared earlier in multiple cultures including ancient Egypt, China, and India.
Leibniz was specifically inspired by the Chinese I Ching. The scribes of ancient Egypt used two different systems for their fractions, Egyptian fractions not related to the binary number system and Horus-Eye fractions so called because many historians of mathematics believe that the symbols used for this system could be arranged to form the eye of Horus , although this has been disputed.
Early forms of this system can be found in documents from the Fifth Dynasty of Egypt , approximately BC, and its fully developed hieroglyphic form dates to the Nineteenth Dynasty of Egypt , approximately BC. The method used for ancient Egyptian multiplication is also closely related to binary numbers. In this method, multiplying one number by a second is performed by a sequence of steps in which a value initially the first of the two numbers is either doubled or has the first number added back into it; the order in which these steps are to be performed is given by the binary representation of the second number.
This method can be seen in use, for instance, in the Rhind Mathematical Papyrus , which dates to around BC. It is based on taoistic duality of yin and yang. The Song Dynasty scholar Shao Yong — rearranged the hexagrams in a format that resembles modern binary numbers, although he did not intend his arrangement to be used mathematically.
The Indian scholar Pingala c. The binary representations in Pingala's system increases towards the right, and not to the left like in the binary numbers of the modern, Western positional notation. The residents of the island of Mangareva in French Polynesia were using a hybrid binary- decimal system before The base-2 system utilized in geomancy had long been widely applied in sub-Saharan Africa. In Francis Bacon discussed a system whereby letters of the alphabet could be reduced to sequences of binary digits, which could then be encoded as scarcely visible variations in the font in any random text.
John Napier in described a system he called location arithmetic for doing binary calculations using a non-positional representation by letters. Thomas Harriot investigated several positional numbering systems, including binary, but did not publish his results; they were found later among his papers.
Leibniz's system uses 0 and 1, like the modern binary numeral system. An example of Leibniz's binary numeral system is as follows: Leibniz interpreted the hexagrams of the I Ching as evidence of binary calculus. Leibniz saw the I Ching hexagrams as an affirmation of the universality of his own religious beliefs as a Christian.
He believed that binary numbers were symbolic of the Christian idea of creatio ex nihilo or creation out of nothing. Now one can say that nothing in the world can better present and demonstrate this power than the origin of numbers, as it is presented here through the simple and unadorned presentation of One and Zero or Nothing.
In , British mathematician George Boole published a landmark paper detailing an algebraic system of logic that would become known as Boolean algebra.
His logical calculus was to become instrumental in the design of digital electronic circuitry. In , Claude Shannon produced his master's thesis at MIT that implemented Boolean algebra and binary arithmetic using electronic relays and switches for the first time in history.
In November , George Stibitz , then working at Bell Labs , completed a relay-based computer he dubbed the "Model K" for " K itchen", where he had assembled it , which calculated using binary addition. Their Complex Number Computer, completed 8 January , was able to calculate complex numbers. In a demonstration to the American Mathematical Society conference at Dartmouth College on 11 September , Stibitz was able to send the Complex Number Calculator remote commands over telephone lines by a teletype.
It was the first computing machine ever used remotely over a phone line. Some participants of the conference who witnessed the demonstration were John von Neumann , John Mauchly and Norbert Wiener , who wrote about it in his memoirs. The Z1 computer , which was designed and built by Konrad Zuse between and , used Boolean logic and binary floating point numbers. Any number can be represented by a sequence of bits binary digits , which in turn may be represented by any mechanism capable of being in two mutually exclusive states.
Any of the following rows of symbols can be interpreted as the binary numeric value of The numeric value represented in each case is dependent upon the value assigned to each symbol. In a computer, the numeric values may be represented by two different voltages ; on a magnetic disk , magnetic polarities may be used.
A "positive", " yes ", or "on" state is not necessarily equivalent to the numerical value of one; it depends on the architecture in use. In keeping with customary representation of numerals using Arabic numerals , binary numbers are commonly written using the symbols 0 and 1. When written, binary numerals are often subscripted, prefixed or suffixed in order to indicate their base, or radix.
The following notations are equivalent:. When spoken, binary numerals are usually read digit-by-digit, in order to distinguish them from decimal numerals. For example, the binary numeral is pronounced one zero zero , rather than one hundred , to make its binary nature explicit, and for purposes of correctness. Since the binary numeral represents the value four, it would be confusing to refer to the numeral as one hundred a word that represents a completely different value, or amount.
Alternatively, the binary numeral can be read out as "four" the correct value , but this does not make its binary nature explicit. Counting in binary is similar to counting in any other number system. Beginning with a single digit, counting proceeds through each symbol, in increasing order.
Before examining binary counting, it is useful to briefly discuss the more familiar decimal counting system as a frame of reference. Decimal counting uses the ten symbols 0 through 9.
Counting begins with the incremental substitution of the least significant digit rightmost digit which is often called the first digit. When the available symbols for this position are exhausted, the least significant digit is reset to 0 , and the next digit of higher significance one position to the left is incremented overflow , and incremental substitution of the low-order digit resumes. This method of reset and overflow is repeated for each digit of significance.
Counting progresses as follows:. Binary counting follows the same procedure, except that only the two symbols 0 and 1 are available. Thus, after a digit reaches 1 in binary, an increment resets it to 0 but also causes an increment of the next digit to the left:. In the binary system, each digit represents an increasing power of 2, with the rightmost digit representing 2 0 , the next representing 2 1 , then 2 2 , and so on.
The equivalent decimal representation of a binary number is sum of the powers of 2 which each digit represents. For example, the binary number is converted to decimal form as follows:. Fractions in binary only terminate if the denominator has 2 as the only prime factor. Arithmetic in binary is much like arithmetic in other numeral systems. Addition, subtraction, multiplication, and division can be performed on binary numerals.
The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:. Adding two "1" digits produces a digit "0", while 1 will have to be added to the next column. This is similar to what happens in decimal when certain single-digit numbers are added together; if the result equals or exceeds the value of the radix 10 , the digit to the left is incremented:.
This is known as carrying. This is correct since the next position has a weight that is higher by a factor equal to the radix. Carrying works the same way in binary:. In this example, two numerals are being added together: The top row shows the carry bits used. The 1 is carried to the left, and the 0 is written at the bottom of the rightmost column.
The second column from the right is added: This time, a 1 is carried, and a 1 is written in the bottom row. Proceeding like this gives the final answer 2 36 decimal. When computers must add two numbers, the rule that: This method is generally useful in any binary addition where one of the numbers contains a long "string" of ones.
It is based on the simple premise that under the binary system, when given a "string" of digits composed entirely of n ones where: That concept follows, logically, just as in the decimal system, where adding 1 to a string of n 9s will result in the number 1 followed by a string of n 0s:.
Such long strings are quite common in the binary system. From that one finds that large binary numbers can be added using two simple steps, without excessive carry operations. In the following example, two numerals are being added together: Instead of the standard carry from one column to the next, the lowest-ordered "1" with a "1" in the corresponding place value beneath it may be added and a "1" may be carried to one digit past the end of the series.
The "used" numbers must be crossed off, since they are already added. Other long strings may likewise be cancelled using the same technique. Then, simply add together any remaining digits normally. Proceeding in this manner gives the final answer of 1 1 0 0 1 1 1 0 0 0 1 2 In our simple example using small numbers, the traditional carry method required eight carry operations, yet the long carry method required only two, representing a substantial reduction of effort. Subtracting a "1" digit from a "0" digit produces the digit "1", while 1 will have to be subtracted from the next column.
This is known as borrowing. The principle is the same as for carrying. Subtracting a positive number is equivalent to adding a negative number of equal absolute value. Computers use signed number representations to handle negative numbers—most commonly the two's complement notation. Such representations eliminate the need for a separate "subtract" operation. Using two's complement notation subtraction can be summarized by the following formula:.
Multiplication in binary is similar to its decimal counterpart. Two numbers A and B can be multiplied by partial products:More...