All Topics  
Binary numeral system

 

   Email Print
   Bookmark   Link






 

Binary numeral system



 
 
The binary numeral system, or notation
Notation

The term notation can refer to:...
 with a radix
Radix

In numeral system, the base or radix is usually the number of unique Numerical digit, including zero, that a Positional notation numeral system uses to represent numbers....
 of 2. Owing to its straightforward implementation in digital electronic circuitry using logic gate
Logic gate

A logic gate performs a logical operation on one or more logic inputs and produces a single logic output. The logic normally performed is Boolean logic and is most commonly found in digital circuits....
s, the binary system is used internally by all modern computer
Computer

A computer is a machine that manipulates Data according to a list of Code .The first devices that resemble modern computers date to the mid-20th century , although the computer concept and various machines similar to computers existed earlier....
s.

ancient Indian writer Pingala
Pingala

Pingala was an Ancient Indian writer, famous for his work, the Chandas Shastra , a Sanskrit treatise on prosody considered one of the Vedanga....
 developed advanced mathematical concepts for describing prosody, and in doing so presented the first known description of a binary numeral system.

A full set of 8 trigram
Bagua (concept)

The Ba gua are eight diagrams used in Taoist cosmology to represent a range of interrelated concepts. Each consists of three lines, each either "broken" or "unbroken," representing a Yin and yang line or a yang line, respectively....
s and 64 hexagram
Hexagram (I Ching)

The I Ching book consists of 64 hexagrams.A hexagram is a figure composed of six stacked horizontal lines , where each line is either Yang , or Yin ....
s, analogous to the 3-bit and 6-bit binary numerals, were known to the ancient Chinese in the classic text
Chinese classic texts

Chinese classic texts or Chinese canonical texts refer to the pre-Qin Dynasty Chinese texts, especially the Confucian Four Books and Five Classics ....
 I Ching
I Ching

The I Ching , or ?Y? Jing? ; also called Classic of Changes or Book of Changes is one of the oldest of the Chinese classic texts....
.






Discussion
Ask a question about 'Binary numeral system'
Start a new discussion about 'Binary numeral system'
Answer questions from other users
Full Discussion Forum



Encyclopedia


The binary numeral system, or notation
Notation

The term notation can refer to:...
 with a radix
Radix

In numeral system, the base or radix is usually the number of unique Numerical digit, including zero, that a Positional notation numeral system uses to represent numbers....
 of 2. Owing to its straightforward implementation in digital electronic circuitry using logic gate
Logic gate

A logic gate performs a logical operation on one or more logic inputs and produces a single logic output. The logic normally performed is Boolean logic and is most commonly found in digital circuits....
s, the binary system is used internally by all modern computer
Computer

A computer is a machine that manipulates Data according to a list of Code .The first devices that resemble modern computers date to the mid-20th century , although the computer concept and various machines similar to computers existed earlier....
s.

History

The ancient Indian writer Pingala
Pingala

Pingala was an Ancient Indian writer, famous for his work, the Chandas Shastra , a Sanskrit treatise on prosody considered one of the Vedanga....
 developed advanced mathematical concepts for describing prosody, and in doing so presented the first known description of a binary numeral system.

A full set of 8 trigram
Bagua (concept)

The Ba gua are eight diagrams used in Taoist cosmology to represent a range of interrelated concepts. Each consists of three lines, each either "broken" or "unbroken," representing a Yin and yang line or a yang line, respectively....
s and 64 hexagram
Hexagram (I Ching)

The I Ching book consists of 64 hexagrams.A hexagram is a figure composed of six stacked horizontal lines , where each line is either Yang , or Yin ....
s, analogous to the 3-bit and 6-bit binary numerals, were known to the ancient Chinese in the classic text
Chinese classic texts

Chinese classic texts or Chinese canonical texts refer to the pre-Qin Dynasty Chinese texts, especially the Confucian Four Books and Five Classics ....
 I Ching
I Ching

The I Ching , or ?Y? Jing? ; also called Classic of Changes or Book of Changes is one of the oldest of the Chinese classic texts....
. An arrangement of the hexagrams of the I Ching, ordered according to the values of the corresponding binary numbers (from 0 to 63), and a method for generating the same, was developed by the Chinese scholar and philosopher Shao Yong
Shao Yong

Shao Yong , courtesy name Yaofu , named Sh?o Kangji? after death, was a Song Dynasty Chinese philosophy, cosmology, poet and historian who greatly influenced the development of Neo-Confucianism in China....
 in the 11th century. However, there is no evidence that Shao understood binary computation; the ordering is also the lexicographical order
Lexicographical order

In mathematics, the lexicographic or lexicographical order, , is a natural order theory structure of the Cartesian product of two ordered sets....
 on sextuples of elements chosen from a two-element set.

Similar sets of binary combinations have also been used in traditional African divination systems such as Ifá
IFA

IFA may refer to:...
 as well as in medieval
Middle Ages

File:Karl 1 mit papst gelasius gregor1 sacramentar v karl d kahlen.jpgThe Middle Ages of European history are a period in history which lasted for roughly a millennium, commonly dated from the fall of the Roman Empire in the 5th century to the beginning of the Early Modern Period in the 16th century, marked by the division of Western Christi...
 Western geomancy
Geomancy

File:Geomantic_instrument_Egypt_or_Syria_1241_1242_CE_Muhammad_ibn_Khutlukh_al_Mawsuli.jpgFile:Geomantic instrument Egypt or Syria 1241 1242 CE detail 1.jpg...
. The base 2 system utilized in geomancy had long been widely applied in sub-Saharan Africa.

In 1605 Francis Bacon
Francis Bacon

Francis Bacon, 1st Viscount St Alban King's Counsel , son of Nicholas Bacon by his second wife Anne Bacon, was an English philosopher, statesman, scientist, lawyer, jurist, and author....
 discussed a system by which 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. Importantly for the general theory of binary encoding, he added that this method could be used with any objects at all: "provided those objects be capable of a twofold difference only; as by Bells, by Trumpets, by Lights and Torches, by the report of Muskets, and any instruments of like nature". (See Bacon's cipher
Bacon's cipher

Bacon's cipher or the Baconian cipher is a method of steganography devised by Francis Bacon. A message is concealed in the presentation of text, rather than its content....
.)

The modern binary number system was fully documented by Gottfried Leibniz
Gottfried Leibniz

Gottfried Wilhelm Leibniz was a Germany polymath who wrote primarily in Latin and French language.He occupies an equally grand place in both the history of philosophy and the history of mathematics....
 in the 17th century in his article Explication de l'Arithmétique Binaire. Leibniz's system used 0 and 1, like the modern binary numeral system. As a Sinophile
Sinophile

A Sinophile is a person who demonstrates a strong interest in aspects of Culture of China or who shows a specific interest in the Greater China region....
, Leibniz was aware of the I Ching and noted with fascination how its hexagrams correspond to the binary numbers from 0 to 111111, and concluded that this mapping was evidence of major Chinese accomplishments in the sort of philosophical mathematics he admired.

In 1854, British
United Kingdom

The United Kingdom of Great Britain and Northern Ireland, commonly known as the United Kingdom , the UK or Britain,is a sovereign state located off the northwestern coast of continental Europe....
 mathematician George Boole
George Boole

George Boole was anEngland mathematician and philosopher.As the inventor of Boolean Logic, which is the basis of modern digital computer logic, Boole is regarded in hindsight as one of the founders of the field of computer science....
 published a landmark paper detailing an algebraic system of logic
Logic

Logic is the study of the principles of valid demonstration and inference. Logic is a branch of philosophy, a part of the classical Trivium . The word derives from Greek language ?????? , fem....
 that would become known as Boolean algebra. His logical calculus was to become instrumental in the design of digital electronic circuitry.

In 1937, 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. Entitled A Symbolic Analysis of Relay and Switching Circuits
A Symbolic Analysis of Relay and Switching Circuits

In his 1937 Massachusetts Institute of Technology master's thesis, A Symbolic Analysis of Relay and Switching Circuits, Claude Elwood Shannon proved that Boolean algebra and binary arithmetic could be used to simplify the arrangement of the electromechanical relays then used in telephone routing switches, then turned the concept upside d...
, Shannon's thesis essentially founded practical digital circuit
Digital circuit

Digital electronics are electronics systems that use digital signals. Digital electronics are representations of Boolean algebra and are used in computers, mobile phones, and other consumer products....
 design.

In November 1937, George Stibitz
George Stibitz

George Robert Stibitz is internationally recognized as a father of the modern digital computer. He was a Bell Labs researcher known for his 1930s and 1940s work on the realization of Boolean logic digital circuits using electromechanical relays as the switching element....
, then working at Bell Labs
Bell Labs

Bell Laboratories is the research organization of Alcatel-Lucent and previously of the American Telephone & Telegraph Company .Bell Laboratories has had its headquarters at Berkeley Heights, New Jersey, and it has research and development facilities throughout the world....
, completed a relay-based computer he dubbed the "Model K" (for "Kitchen", where he had assembled it), which calculated using binary addition. Bell Labs thus authorized a full research program in late 1938 with Stibitz at the helm. Their Complex Number Computer, completed January 8, 1940, was able to calculate complex numbers. In a demonstration to the American Mathematical Society
American Mathematical Society

The American Mathematical Society is an association of professional mathematicians dedicated to the interests of mathematics research and scholarship, which it does with various publications and conferences as well as annual monetary awards and prizes to mathematicians....
 conference at Dartmouth College
Dartmouth College

Dartmouth College is a private university, coeducational university located in Hanover, New Hampshire, New Hampshire. Incorporated as "Trustees of Dartmouth College,"...
 on September 11, 1940, 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 von Neumann

John von Neumann was a Hungarian American mathematician who made major contributions to a vast range of fields, including set theory, functional analysis, quantum mechanics, ergodic theory, continuous geometry, economics and game theory, computer science, numerical analysis, hydrodynamics , and statistics, as well as many other mathematical...
, John Mauchly
John Mauchly

John William Mauchly was an United States physicist who, along with J. Presper Eckert, designed ENIAC, the first general purpose electronic digital computer, as well as EDVAC, BINAC and UNIVAC I, the first commercial computer made in the United States....
, and Norbert Wiener
Norbert Wiener

Norbert Wiener was an United States theoretical and applied math mathematician.Wiener was a pioneer in the study of stochastic processes and noise processes, contributing work relevant to electronic engineering, electronic communication, and control systems....
, who wrote about it in his memoirs.

Representation


A binary number can be represented by any sequence of bit
Bit

A bit is a binary numeral system numerical digit, taking a value of either 0 or 1. Binary digits are a basic unit of information Computer data storage and transmission in digital computing and digital information theory....
s (binary digits), which in turn may be represented by any mechanism capable of being in two mutually exclusive states. The following sequences of symbols could all be interpreted as the binary numeric value of 667:

1 0 1 0 0 1 1 0 1 1 | - | - - | | - | | x o x o o x x o x x y n y n n y y n y y

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 voltage
Voltage

Electrical tension is the potential difference between two points of an electrical or electronic circuit, expressed in volts. It is the measurement of the potential for an electric field to cause an electric current in an electrical conductor....
s; on a magnetic
Magnetic field

A magnetism field is a vector field which can exert a magnetic force on moving electric charges and on magnetic dipoles . When placed in a magnetic field, magnetic dipoles tend to align their axes parallel to the magnetic field....
 disk
Disk storage

Disk storage is a general category of a computer storage mechanisms, in which data is recorded on planar, round and rotating surfaces . A disk drive is a peripheral device used to record and retrieve information....
, magnetic polarities
Polarity

In physics, polarity is a description of an attribute, typically a binary attribute , or a vector . For example:* An electric charge has a polarity of either positive or negative....
 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
Arabic numerals

The 'arabic numerals', or 'Hindu numerals' are the ten digits , which?along with Decimal Number System by which a sequence was read as a number?were originally defined by Indian mathematics, later modified and transferred to North African Islamic mathematics and transmitted to Europe in the Middle Ages, whence they spread around the wo...
, 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:

100101 binary (explicit statement of format)
100101b (a suffix indicating binary format)
100101B (a suffix indicating binary format)
bin 100101 (a prefix indicating binary format)
1001012 (a subscript indicating base-2 (binary) notation)
%100101 (a prefix indicating binary format)
0b100101 (a prefix indicating binary format, common in programming languages)


The final notation is used if converting using Google
Google

Google Inc. is an United States public company, earning revenue from AdWords related to its Google search, Gmail, Google Maps, Google Apps, Orkut, and YouTube services as well as selling advertising-free versions of the Google Search Appliance....
. For example searching in google results in 5 = 0b101.

When spoken, binary numerals are usually read digit-by-digit, in order to distinguish them from decimal numbers. For example, the binary numeral 100 is pronounced one zero zero, rather than one hundred, to make its binary nature explicit, and for purposes of correctness. Since the binary numeral 100 is equal to the decimal value four, it would be confusing, and numerically incorrect, to refer to the numeral as one hundred.

Counting in binary

Binary Decimal
00
11
102
113
1004
1015
1106
1117
10008
10019
101010
Since binary is a base-2 system, each digit represents an increasing power of 2, with the rightmost digit representing 20, the next representing 21, then 22, and so on. To determine the decimal representation of a binary number simply take the sum of each of the product binary digits with the power of 2 which they represent. For example, the binary number:

100101

is converted to decimal form by:

[(1) × 25] + [(0) × 24] + [(0) × 23] + [(1) × 22] + [(0) × 21] + [(1) × 20] =

[1 × 32] + [0 × 16] + [0 × 8] + [1 × 4] + [0 × 2] + [1 × 1] = 37

To create higher numbers, additional digits are simply added to the left side of the binary representation.

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. Decimal counting uses the symbols 0 through 9, while binary only uses the symbols 0 and 1.

When the symbols for the first digit are exhausted, the next-higher digit (to the left) is incremented, and counting starts over at 0. In decimal
Decimal

The decimal numeral system has 10 as its Base . It is the most widely used numeral system....
, counting proceeds like so:

000, 001, 002, ... 007, 008, 009, (rightmost digit starts over, and next digit is incremented)
010, 011, 012, ...
   ...
090, 091, 092, ... 097, 098, 099, (rightmost two digits start over, and next digit is incremented)
100, 101, 102, ...


After a digit reaches 9, an increment resets it to 0 but also causes an increment of the next digit to the left. In binary, counting is the same except that only the two symbols 0 and 1 are used. 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:

0000,
0001, (rightmost digit starts over, and next digit is incremented)
0010, 0011, (rightmost two digits start over, and next digit is incremented)
0100, 0101, 0110, 0111, (rightmost three digits start over, and the next digit is incremented)
1000, 1001, ...


Binary arithmetic


Arithmetic in binary is much like arithmetic in other numeral systems. Addition, subtraction, multiplication, and division can be performed on binary numerals.

Addition


The simplest arithmetic operation in binary is addition
Addition

Addition is the mathematics process of putting things together. The plus sign "+" means that numbers are added together. For example, in the picture on the right, there are 3 + 2 apples?meaning three apples and two other apples?which is the same as five apples, since 3 + 2 = 5....
. Adding two single-digit binary numbers is relatively simple, using a form of carrying:

0 + 0 ? 0
0 + 1 ? 1
1 + 0 ? 1
1 + 1 ? 0, carry 1 (since 1 + 1 = 0 + 1 × 10 in binary)
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:

5 + 5 ? 0, carry 1 (since 5 + 5 = 0 + 1 × 10)
7 + 9 ? 6, carry 1 (since 7 + 9 = 6 + 1 × 10)


This is known as carrying. When the result of an addition exceeds the value of a digit, the procedure is to "carry" the excess amount divided by the radix (that is, 10/10) to the left, adding it to the next positional value. 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:

1 1 1 1 1 (carried digits) 0 1 1 0 1 + 1 0 1 1 1 ------------- = 1 0 0 1 0 0

In this example, two numerals are being added together: 011012 (13 decimal) and 101112 (23 decimal). The top row shows the carry bits used. Starting in the rightmost column, 1 + 1 = 102. 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: 1 + 0 + 1 = 102 again; the 1 is carried, and 0 is written at the bottom. The third column: 1 + 1 + 1 = 112. This time, a 1 is carried, and a 1 is written in the bottom row. Proceeding like this gives the final answer 1001002 (36 decimal).

When computers must add two numbers, the rule that: x xor y = (x + y) mod 2 for any two bits x and y allows for very fast calculation, as well.

Subtraction


Subtraction
Subtraction

Subtraction is one of the four basic arithmetic operations; it is the inverse of addition, meaning that if we start with any number and add any number and then subtract the same number we added, we return to the number we started with....
 works in much the same way:

0 − 0 ? 0
0 − 1 ? 1, borrow 1
1 − 0 ? 1
1 − 1 ? 0
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. When the result of a subtraction is less than 0, the least possible value of a digit, the procedure is to "borrow" the deficit divided by the radix (that is, 10/10) from the left, subtracting it from the next positional value.

* * * * (starred columns are borrowed from) 1 1 0 1 1 1 0 - 1 0 1 1 1 ---------------- = 1 0 1 0 1 1 1

Subtracting a positive number is equivalent to adding a negative
Negative and non-negative numbers

A negative number is a real number that is inequality 0 , such as -3. A positive number is a real number that is greater than zero, such as 2....
 number of equal absolute value
Absolute value

In mathematics, the absolute value of a real number is its numerical value without regard to its Negative and non-negative numbers. So, for example, 3 is the absolute value of both 3 and -3....
; computers typically use two's complement
Two's complement

The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of two .A two's-complement system or two's-complement arithmetic is a system in which negative numbers are represented by the two's complement of the absolute value; this system is the most common Signed number r...
 notation to represent negative values. This notation eliminates the need for a separate "subtract" operation. Using two's complement notation subtraction can be summarized by the following formula:

A - B = A + not B + 1

For further details, see two's complement
Two's complement

The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of two .A two's-complement system or two's-complement arithmetic is a system in which negative numbers are represented by the two's complement of the absolute value; this system is the most common Signed number r...
.

Multiplication


Multiplication
Multiplication

Multiplication is the Operation of scaling one number by another. It is one of the four basic operations in elementary arithmetic .Multiplication is defined for Natural number in terms of repeated addition; for example, 4 multiplied by 3 can be calculated by adding 3 copies of 4 together:...
 in binary is similar to its decimal counterpart. Two numbers A and B can be multiplied by partial products: for each digit in B, the product of that digit in A is calculated and written on a new line, shifted leftward so that its rightmost digit lines up with the digit in B that was used. The sum of all these partial products gives the final result.

Since there are only two digits in binary, there are only two possible outcomes of each partial multiplication:

  • If the digit in B is 0, the partial product is also 0
  • If the digit in B is 1, the partial product is equal to A


For example, the binary numbers 1011 and 1010 are multiplied as follows:

1 0 1 1 (A) × 1 0 1 0 (B) --------- 0 0 0 0 ? Corresponds to a zero in B + 1 0 1 1 ? Corresponds to a one in B + 0 0 0 0 + 1 0 1 1 --------------- = 1 1 0 1 1 1 0

Binary numbers can also be multiplied with bits after a binary point:

1 0 1.1 0 1 (A) (5.625 in decimal) × 1 1 0.0 1 (B) (6.25 in decimal) ------------- 1 0 1 1 0 1 ? Corresponds to a one in B + 0 0 0 0 0 0 ? Corresponds to a zero in B + 0 0 0 0 0 0 + 1 0 1 1 0 1 + 1 0 1 1 0 1 ----------------------- = 1 0 0 0 1 1.0 0 1 0 1 (35.15625 in decimal)

See also Booth's multiplication algorithm
Booth's multiplication algorithm

Booth's multiplication algorithm is a multiplication algorithm that multiplies two signed base 2 numbers in two's complement....
.

Division


Binary division
Division (mathematics)

In mathematics, especially in elementary arithmetic, division is an arithmetic operation which is the inverse of multiplication.Specifically, if c times b equals a, written:...
 is again similar to its decimal counterpart:

___________ 1 0 1 ) 1 1 0 1 1

Here, the divisor is 1012, or 5 decimal, while the dividend is 110112, or 27 decimal. The procedure is the same as that of decimal long division
Long division

In arithmetic, long division is the standard algorithm suitable for dividing simple or complex multidigit numbers. It breaks down a division problem into a series of easier steps....
; here, the divisor 1012 goes into the first three digits 1102 of the dividend one time, so a "1" is written on the top line. This result is multiplied by the divisor, and subtracted from the first three digits of the dividend; the next digit (a "1") is included to obtain a new three-digit sequence:

1 ___________ 1 0 1 ) 1 1 0 1 1 - 1 0 1 ----- 0 1 1

The procedure is then repeated with the new sequence, continuing until the digits in the dividend have been exhausted:

1 0 1 ___________ 1 0 1 ) 1 1 0 1 1 - 1 0 1 ----- 0 1 1 - 0 0 0 ----- 1 1 1 - 1 0 1 ----- 1 0

Thus, the quotient of 110112 divided by 1012 is 1012, as shown on the top line, while the remainder, shown on the bottom line, is 102. In decimal, 27 divided by 5 is 5, with a remainder of 2.

Bitwise operations

Though not directly related to the numerical interpretation of binary symbols, sequences of bits may be manipulated using Boolean
Boolean operation

Boolean operation may refer to one of the following related meanings.*Boolean function*an operation in a Boolean algebra ; in particular:**operations over the algebra of sets: union , intersection , etc....
 logical operators. When a string of binary symbols is manipulated in this way, it is called a bitwise operation
Bitwise operation

In computer programming, a bitwise operation operates on one or two bit patterns or Binary numeral system at the level of their individual bits....
; the logical operators AND
Logical conjunction

In logic and/or mathematics, logical conjunction or and is a two-place logical operation that results in a value of true if both of its operands are true, otherwise a value of false....
, OR
Logical disjunction

File:ORGate2.pngIn logic and mathematics, or, also known as logical disjunction or inclusive disjunction is a logical operator that results in true whenever one or more of its operands are true....
, and XOR
Exclusive disjunction

The Logical connective exclusive disjunction, also called exclusive or , is a type of logical disjunction on two operands that results in a value of true if and only if exactly one of the operands has a value of true....
 may be performed on corresponding bits in two binary numerals provided as input. The logical NOT
Negation

In logic and mathematics, negation or not is an operation on logical values, for example, the logical value of a proposition, that sends true to false and false to true....
 operation may be performed on individual bits in a single binary numeral provided as input. Sometimes, such operations may be used as arithmetic short-cuts, and may have other computational benefits as well. For example, an arithmetic shift
Arithmetic shift

In computer programming, an arithmetic shift is a shift operator, sometimes known as a signed shift . For binary numeral systems it is a bitwise operation that shifts all of the bits of its operand; every bit in the operand is simply moved a given number of bit positions, and the vacant bit-positions are filled in....
 left of a binary number is the equivalent of multiplication by a (positive, integral) power of 2.

Conversion to and from other numeral systems


Decimal


To convert from a base-10 integer numeral to its base-2 (binary) equivalent, the number is divided by two, and the remainder is the least-significant bit. The (integer) result is again divided by two, its remainder is the next most significant bit. This process repeats until the result of further division becomes zero.

Conversion from base-2 to base-10 proceeds by applying the preceding algorithm, so to speak, in reverse. The bits of the binary number are used one by one, starting with the most significant bit. Beginning with the value 0, repeatedly double the prior value and add the next bit to produce the next value. This can be organized in a multi-column table. For example to convert 100101011012 to decimal:

10010101101>
Prior value× 2 +Next BitNext value
= 0
0 × 2 + 1 = 1
1 × 2 + 0 = 2
2 × 2 + 0 = 4
4 × 2 + 1 = 9
9 × 2 + 0 = 18
18 × 2 + 1 = 37
37 × 2 + 0 = 74
74 × 2 + 1 = 149
149 × 2 + 1 = 299
299 × 2 + 0 = 598
598 × 2 + 1 = 1197


The result is 119710. This method is an application of the Horner scheme
Horner scheme

In numerical analysis, the Horner scheme or Horner algorithm, named after William George Horner, is an algorithm for the efficient evaluation of polynomials in Monomial basis....
.

Bin: 10 0 1 0 1 0 1 1 0 1

Dec: 1×2^10 + 0×2^9 + 0×2^8 + 1×2^7 + 0×2^6 + 1×2^5 + 0×2^4 + 1×2^3 + 1×2^2 + 0×2^1 + 1×2^0 = 1197

The fractional parts of a number are converted with similar methods. They are again based on the equivalence of shifting with doubling or halving.

In a fractional binary number such as .110101101012, the first digit is , the second , etc. So if there is a 1 in the first place after the decimal, then the number is at least , and vice versa. Double that number is at least 1. This suggests the algorithm: Repeatedly double the number to be converted, record if the result is at least 1, and then throw away the integer part.

For example, 10, in binary, is:

ConvertingResult
0.
0.0
0.01
0.010
0.0101


Thus the repeating decimal fraction 0.... is equivalent to the repeating binary fraction 0.... .

Or for example, 0.110, in binary, is:

Converting Result
0.1 0.
0.1 × 2 = 0.2 < 1 0.0
0.2 × 2 = 0.4 < 1 0.00
0.4 × 2 = 0.8 < 1 0.000
0.8 × 2 = 1.6 = 1 0.0001
0.6 × 2 = 1.2 = 1 0.00011
0.2 × 2 = 0.4 < 1 0.000110
0.4 × 2 = 0.8 < 1 0.0001100
0.8 × 2 = 1.6 = 1 0.00011001
0.6 × 2 = 1.2 = 1 0.000110011
0.2 × 2 = 0.4 < 1 0.0001100110


This is also a repeating binary fraction 0.00011... . It may come as a surprise that terminating decimal fractions can have repeating expansions in binary. It is for this reason that many are surprised to discover that 0.1 + ... + 0.1, (10 additions) differs from 1 in floating point arithmetic. In fact, the only binary fractions with terminating expansions are of the form of an integer divided by a power of 2, which 1/10 is not.

The final conversion is from binary to decimal fractions. The only difficulty arises with repeating fractions, but otherwise the method is to shift the fraction to an integer, convert it as above, and then divide by the appropriate power of two in the decimal base. For example:

= 1100 .1011100...
= 1100101110.01110...
= 11001 .01110...
= 1100010101
= (789/62)10


Another way of converting from binary to decimal, often quicker for a person familiar with hexadecimal
Hexadecimal

In mathematics and computer science, hexadecimal is a numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 09 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen....
, is to do so indirectly—first converting ( in binary) into ( in hexadecimal) and then converting ( in hexadecimal) into ( in decimal).

For very large numbers, these simple methods are inefficient because they perform a large number of multiplications or divisions where one operand is very large. A simple divide-and-conquer algorithm is more effective asymptotically: given a binary number, it is divided by 10k, where k is chosen so that the quotient roughly equals the remainder; then each of these pieces is converted to decimal and the two are concatenated
Concatenation

In computer programming, string concatenation is the operation of joining two character string end to end. For example, the strings "snow" and "ball" may be concatenated to give "snowball"....
. Given a decimal number, it can be split into two pieces of about the same size, each of which is converted to binary, whereupon the first converted piece is multiplied by 10k and added to the second converted piece, where k is the number of decimal digits in the second, least-significant piece before conversion.

Hexadecimal

Binary may be converted to and from hexadecimal
Hexadecimal

In mathematics and computer science, hexadecimal is a numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 09 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen....
 somewhat more easily. This is because the radix
Radix

In numeral system, the base or radix is usually the number of unique Numerical digit, including zero, that a Positional notation numeral system uses to represent numbers....
 of the hexadecimal system (16) is a power of the radix of the binary system (2). More specifically, 16 = 24, so it takes four digits of binary to represent one digit of hexadecimal.

The following table shows each hexadecimal digit along with the equivalent decimal value and four-digit binary sequence:

To convert a hexadecimal number into its binary equivalent, simply substitute the corresponding binary digits:

3A16 = 0011 10102
E716 = 1110 01112


To convert a binary number into its hexadecimal equivalent, divide it into groups of four bits. If the number of bits isn't a multiple of four, simply insert extra 0 bits at the left (called padding
Padding

In fashion, padding is material sometimes added to clothes. It is often done in an attempt to enhance appearance by 'improving' a physical feature, often a sexually significant one....
). For example:

10100102 = 0101 0010 grouped with padding = 5216
110111012 = 1101 1101 grouped = DD16


To convert a hexadecimal number into its decimal equivalent, multiply the decimal equivalent of each hexadecimal digit by the corresponding power of 16 and add the resulting values:

C0E716 = (12 × 163) + (0 × 162) + (14 × 161) + (7 × 160) = (12 × 4096) + (0 × 256) + (14 × 16) + (7 × 1) = 49,38310


Octal


Binary is also easily converted to the octal
Octal

The octal numeral system, or oct for short, is the radix-8 number system, and uses the digits 0 to 7. Numerals can be made from Binary numeral system numerals by grouping consecutive digits into groups of three ....
 numeral system, since octal uses a radix of 8, which is a power of two
Power of two

In mathematics, a power of two is any of the integer exponentiation of the number 2 ; in other words, two multiplication by itself a certain number of times....
 (namely, 23, so it takes exactly three binary digits to represent an octal digit). The correspondence between octal and binary numerals is the same as for the first eight digits of hexadecimal
Hexadecimal

In mathematics and computer science, hexadecimal is a numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 09 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen....
 in the table above. Binary 000 is equivalent to the octal digit 0, binary 111 is equivalent to octal 7, and so forth.

OctalBinary
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111


Converting from octal to binary proceeds in the same fashion as it does for hexadecimal
Hexadecimal

In mathematics and computer science, hexadecimal is a numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 09 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen....
:

658 = 110 1012
178 = 001 1112


And from binary to octal:

1011002 = 101 1002 grouped = 548
100112 = 010 0112 grouped with padding = 238


And from octal to decimal:

658 = (6 × 81) + (5 × 80) = (6 × 8) + (5 × 1) = 5310
1278 = (1 × 82) + (2 × 81) + (7 × 80) = (1 × 64) + (2 × 8) + (7 × 1) = 8710


Representing real numbers


Non-integers can be represented by using negative powers, which are set off from the other digits by means of a radix point
Radix point

In mathematics and computing, a radix point is the symbol used in numerical representations to separate the integer part of a number from its fraction part ....
 (called a decimal point in the decimal system). For example, the binary number 11.012 thus means:

1 × 21 (1 × 2 = 2) plus
1 × 20 (1 × 1 = 1) plus
0 × 2-1 (0 × ½ = 0) plus
1 × 2-2 (1 × ¼ = 0.25)


For a total of 3.25 decimal.

All dyadic rational numbers have a terminating binary numeral—the binary representation has a finite number of terms after the radix point. Other rational number
Rational number

In mathematics, a rational number is a number which can be expressed as a quotient of two integers. Non-integer rational numbers are usually written as the vulgar fraction , where b is not 0 ....
s have binary representation, but instead of terminating, they recur, with a finite sequence of digits repeating indefinitely. For instance

= = 0.01010101...2

= = 0.10110100 10110100 ...2

The phenomenon that the binary representation of any rational is either terminating or recurring also occurs in other radix-based numeral systems. See, for instance, the explanation in decimal
Decimal

The decimal numeral system has 10 as its Base . It is the most widely used numeral system....
. Another similarity is the existence of alternative representations for any terminating representation, relying on the fact that 0.111111... is the sum of the geometric series
Geometric series

In mathematics, a geometric series is a series with a constant ratio between successive term . For example, the seriesis geometric, because each term is equal to half of the previous term....
 2-1 + 2-2 + 2-3 + ... which is 1.

Binary numerals which neither terminate nor recur represent irrational number
Irrational number

In mathematics, an irrational number is any real number that is not a rational number ? that is, it is a number which cannot be expressed as a fraction m/n, where m and n are integers, with n non-zero....
s. For instance,
  • 0.10100100010000100000100.... does have a pattern, but it is not a fixed-length recurring pattern, so the number is irrational
  • 1.0110101000001001111001100110011111110... is the binary representation of , the square root
    Square root

    In mathematics, a square root of a number x is a number r such that r2 = x, or, in other words, a number r whose square is x....
     of 2, another irrational. It has no discernible pattern. See irrational number
    Irrational number

    In mathematics, an irrational number is any real number that is not a rational number ? that is, it is a number which cannot be expressed as a fraction m/n, where m and n are integers, with n non-zero....
    .


See also

  • Two's complement
    Two's complement

    The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of two .A two's-complement system or two's-complement arithmetic is a system in which negative numbers are represented by the two's complement of the absolute value; this system is the most common Signed number r...
  • Redundant binary representation
    Redundant binary representation

    A redundant binary representation is a numeral system that uses more bits than needed to represent a single binary Numerical digit so that most numbers have several representations....
  • Finger binary
    Finger binary

    Finger binary is a system for Finger counting and displaying Binary numeral system on the fingers and thumbs of one or more hands. It is possible to count from 0 to 31 using the fingers of a single hand, or from 0 through 1023 if both hands are used....
  • Binary-coded decimal
    Binary-coded decimal

    In computing and electronics systems, binary-coded decimal is an encoding for decimal numbers in which each digit is represented by its own binary sequence....
  • Gray code
    Gray code

    |}The reflected binary code, also known as Gray code after Frank Gray , is a binary numeral system where two successive values differ in only one bit....
  • Offset binary
    Offset binary

    Offset binary is a digital coding scheme where all-zero corresponds to the minimal negative value and all-one to the Integer_overflow. There is no standard for offset binary, but most often the "zero" value is represented by a 1 in the most significant bit and zero in all other bits....
  • linear feedback shift register
    Linear feedback shift register

    A linear feedback shift register is a shift register whose input bit is a Linear transformation function of its previous state.The only linear functions of single bits are xor and inverse-xor; thus it is a shift register whose input bit is driven by the exclusive-or of some bits of the overall shift register value....
  • SZTAKI Desktop Grid
    SZTAKI Desktop Grid

    SZTAKI Desktop Grid is a Berkeley Open Infrastructure for Network Computing project located in Hungary run by the Computer and Automation Research Institute of the Hungarian Academy of Sciences....
     searches for generalized binary number systems up to dimension 11.


External links


  • at cut-the-knot
    Cut-the-knot

    Cut-the-knot is an educational website maintained by Alexander Bogomolny and devoted to popular exposition of a great variety of topics in mathematics....
  • at cut-the-knot
    Cut-the-knot

    Cut-the-knot is an educational website maintained by Alexander Bogomolny and devoted to popular exposition of a great variety of topics in mathematics....
  • at Math Is Fun
    Math Is Fun

    Math Is Fun is an educational website maintained by Rod Pierce devoted to the concept that mathematics is, indeed, fun.There are several aspects to the website:...
  • at wikiHow
    WikiHow

    wikiHow is a wiki-based community with an extensive database of how-to guides. All of the site's content is licensed under Creative Commons ; and the site uses a modified version of MediaWiki 1.12....