Binary Numbers in Ancient India

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 2nd century A.D., more than 1500 years before their discovery in the west.

Ancient India had a tradition of scholarly learning. This tradition continued till the beginning of current millennium. During the millennium long foreign rule hostile to scholarly activities, a vast body of scientific information was lost. Thankfully some of the ancient literature has survived. Most of the scholarly work needed to preserve the ancient learning was done in South India which remained free from invasion for a significant time. Scholars are now rediscovering the forgotten contributions of ancient India in the field of mathematics and science. One of these discoveries is that of the use of Binary numbers for the classification of meters.

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 2nd century A.D. The main commentaries on "Chhandahshastra" are "Vrittaratnakara" by Kedara in probably 8th century, "Tatparyatika" by Trivikrama in 12th century and "Mritasanjivani" by Halayudha in 13th century. 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.

This subject has been discussed in detail in a scholarly article (B. van Nooten, "Binary Numbers in Indian Antiquity", Journal of Indian Studies, Volume 21, 1993, pp. 31-50). This article along with several other articles pertaining to the contribution of ancient India to the field of computer science has been published in a book titled "Computing Science in Ancient India" edited by T. R. N. Rao and Subhash Kak.