Biology and computing seem more distant than they really are. This article explains how DNA is represented in binary and features an introduction to entropy.
The genetic alphabet
DNA, the “molecule of life”, contains an organism’s genetic information. In each of its two strands, DNA encodes this information using an alphabet consisting of molecules called nucleotides. There are 4 kinds of nucleotides in DNA: Adenine (A), Guanine (G), Cytosine (C) and Thymine (T). The letters A, C, G and T thus make up the genetic alphabet. When lined up in a sequence, these letters can be used by cells to define how, and out of which material, proteins (the “sentences” of a cell) are made of.
The computer alphabet
Binary is representation of numbers using a sequence of two symbols, ‘0’ and ‘1’, called bits. For example, 9 can be represented as 1001 in binary [see ‘Background Information’ below for more details]. To represent the decimal number N in binary (base 2), you need log2 N bits.
Bits of DNA
We can use decimal numbers to represent all four nucleotides:
0 for A
1 for G
2 for C
3 for T
To do the same in binary, we would require: log2 (4 nucleotides) = 2 bits.
Namely:
00 for A
01 for G
10 for C
11 for T
Since A and G are chemical compounds classified as purines, we can say that when the most-significant bit (i.e. left-most bit) is 0, we’re dealing with a purine. On the other hand, C and T are classified as pyrimidines since their most-significant bit is 1.
Applications to “every-day life”
Picture yourself at a party, where you are asked to guess which nucleotide your friend Bob has in mind, using only “yes” or “no” questions. The silly approach would be to iterate through all four nucleotides. A more efficient way of tackling this challenge is to first ask whether the nucleotide is a purine or a pyrimidine. In doing so, you reduce the set of possible answers to only 2 nucleotides. What’s more, G and C typically form stronger bonds than A and T. Thus, our second question would be whether the nucleotide tends to form strong bonds. This would allow us to pinpoint the nucleotide our friend was thinking about. Hence, in 2 questions, we are guaranteed to win every time.
Here’s the decision tree:

How can we quantify all this? That’s right, entropy!
Entropy
Entropy can be vaguely defined as the number of questions we need to ask our friend to guess his nucleotide. Here, I will use N to denote a random variable whose value is either A, C, T or G. Then, P(x) represents the probability that Bob’s nucleotide is x. Bearing that in mind, the entropy H is defined as:
H = – ∑ P(x) log2 P(x).
Note that this is a sum over all 4 values of N. If our friend has no nucleotide preference, he is equally likely to choose between the 4 nucleotides, and so: P(A) = P(C) = P(T) = P(G) = ¼. Applying the formula above, we get:
H = – ( ¼ log2 ¼ + ¼ log2 ¼ + ¼ log2 ¼ + ¼ log2 ¼ ) = 2
i.e., we need to ask 2 questions, as expected! As such, entropy only says we cannot ask less than 2 two questions to be sure of our guess, but says nothing of the nature of these questions.
Interestingly, we can do the same analysis for different scenarios. If, for instance, our friend prefers purines, then: P(A) = P(G) = 1/2 and P(C) = P(T) = 0. Plugging that in the entropy equation, we get H = 1. Hence, we only need to ask one question, namely if the nucleotide forms a weak or strong bond.
Let’s try yet another case: if Bob mistakenly reveals he chose A as a nucleotide, then: P(A) = 1 and P(C) = P(T) = P(G) = 0. Applying the entropy formula above, we obtain H = 0, that is, we don’t need to ask Bob any questions: we already know he chose A!
BACKGROUND INFORMATION
As another example, we can represent a certain decimal number as 1110 in binary using 4 bits. What is that decimal number? We look at each bit starting from the right: Each bit corresponds to a power of 2, depending on its position:
1 1 1 0
23 22 21 20
If we use the convention that ‘0’ means ‘false’ and ‘1’ means ‘true’, then we can add up all the powers of two that have a ‘1’ above: 23 + 22 + 21 = 14. So 1110 in binary is 14 in decimal. If we add up all the powers of 2, regardless of whether they have a ‘0’ or a ‘1’ above them, we obtain: 23 + 22 + 21 + 20 = 15, the biggest number that you can represent using 4 bits, 0 being the smallest