# Invention of Binary system in Ancient India by Pingala Rishi

http://www.vedicresearchfoundation.org/binary-system/

Binary numbers form the basis for the operation of computers. Binary numbers were discovered in the west by German mathematician Gottfried Leibniz in 1695. However, new evidence proves that binary numbers were used in India prior to 4 BC, more than 2000 years before their discovery in the west.
The source of this discovery is a text of music by Pingala named “Chhandahshastra” meaning science of meters. This text falls under the category of “Sutra” or aphorismic statements. Detailed discussions of these short but profound statements are found in later commentaries. “Chhandahshastra” can be conservatively dated to atleast 4 BC. The full significance of Pingala’s work can be understood by the explanations found in these three commentaries.
Pingala (Chhandahshastra 8.23) describes the formation of a matrix in order to give a unique value to each meter. An example of such a matrix is as follows:
0 0 0 0 numerical value 1
1 0 0 0 numerical value 2
0 1 0 0 numerical value 3
1 1 0 0 numerical value 4
0 0 1 0 numerical value 5
1 0 1 0 numerical value 6
0 1 1 0 numerical value 7
1 1 1 0 numerical value 8
0 0 0 1 numerical value 9
1 0 0 1 numerical value 10
0 1 0 1 numerical value 11
1 1 0 1 numerical value 12
0 0 1 1 numerical value 13
1 0 1 1 numerical value 14
0 1 1 1 numerical value 15
1 1 1 1 numerical value 16
Following comments are in order:
1. Pingala’s system of binary numbers starts with number one (and not zero). The numerical value is obtained by adding one to the sum of place values.
2. In Pingala’s system the place value increases to the right, unlike the modern notation in which it increases towards the left. This also proves that these two systems developed independently.
Pingala (Chhandahshastra 8.24-25) also describes how to find the binary equivalent of a decimal number. The procedure is as follows:
1. Divide the number by two. If divisible write 1, else write 0 on ground.
2. If first division yielded 1, divide again by two. If divisible write 1, else write 0 to the right of first 1.
3. If first division yielded 0, add one to the remaining number and divide by two. If divisible write 1, else write 0 to the right of first 0.
4. Continue this procedure till you get zero as the remaining number.
To illustrate this procedure let us find the binary equivalent of number 108.
Step 1: Divide by two. Divisible, so write 1. Remaining number is 54.
1
Step 2: Divide number 54 by 2. Divisible, so write 1 next to first 1. Remaining number is 27.
1 1
Step 3: Divide 27 by 2. Indivisible, so write 0 to the right. Add 1 to 27 and divide by 2. Remaining number is 14.
1 1 0
Step 4: Divide 14 by 2. Divisible, so write 1 to the right. Remaining number is 7.
1 1 0 1
Step 5: Divide 7 by 2. Indivisible, so write 0 to the right. Add 1 to 7 and divide by two. Remaining number is 4.
1 1 0 1 0
Step 6: Divide 4 by 2. Divisible, so write 1 to the right. Remaining number is 2.
1 1 0 1 0 1
Step 7: Divide 2 by 2. Divisible, so write 1 to the right. Remaining number is 0. So procedure terminates.
1 1 0 1 0 1 1
Now we can check that this number does represent 108 in Pingala’s system. Taking the sum of place values we get 107 (1*1 + 1*2 + 0*4 + 1*8 + 0*16 + 1*32 + 1*64). Adding 1 to this sum, we get 108, the number we started with.