The Binary Number System and The Binary Code
All digital computers and devices based on computers – including large mainframe computers, minicomputers, supercomputers, desktop systems, laptops, server systems, gaming systems, mobile devices, including cell phones, as well as a host of embedded systems that are found in everyday appliances, automobiles, televisions, etc. – have their foundation built on the binary numbering system and Boolean logic, as this logic is used to implement digital circuits which run the devices listed above.
The main purpose of the binary number system in digital devices is to represent information in an electronic or magnetic machine. The binary system is clear, unambiguous, and reliable, as it based on only two numbers: 0 and 1, representing “off” or “on”. The binary number system is used for internally representing all numbers and codes required in a digital system. It is computer-oriented, although they are also readily understood by humans, who normally work with the base-10, or decimal, number system. The binary system uses base-2 numbers, which are used for all codes, including base-2 codes for characters. In digital computers (and devices in general), binary numbers are essentially “hidden” from the user. The user is exposed only to the external representation of binary numbers, which is oriented towards representations with which humans are familiar. Standard base-10 numbers – both integers (whole numbers) and floating point (non-integer numbers, fractional numbers, or irrational numbers) – and keyboard characters are manifestations of these external representations.
The binary numbering system is therefore a base-2 positional numbering system. This can be illustrated by first examining the familiar base-10 system in detail. The following is a review of this numbering system, and how values can be represented within this system. It will serve as a basis for the discussion of the binary number system, and base-2 representations used in digital computer systems, that follow.
The “base” in base-10 indicates that there are ten digits, or primitive numbers, that are used as a basis for all numbers in the system. Of course, the ten digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. From exponentiation, the base of a system is the number that is raised to a power, known as the exponent. In the base-10 system, each place, or position in a number corresponds to a power (exponent) of 10 (the base). Some powers of 10 used in the base-10 system are:
10 = 1
101 = 10 (ten, or 1 with one zero)
102 = 100 (one hundred, or 1 with two zeros)
103 = 1000 (one thousand, or 1 with three zeros)
In general, if n is a non-negative integer (any positive integer, with zero included), then
10n = 1 with n zeros.
Any integer can be represented as a sum of powers of 10. For example, the number 29 is represented as:
29 = (2 x 101) + (9 x 100)
The number 78,318 is represented as:
78,318 = (7 x 104) + (3 x 103) + (3 x 102) + (1 x 101) + (8 x 100)
Similarly, 1,001,200 is represented as:
1,001,200 = (1 x 106) + (0 x 105) + (0 x 104) + (1 x 103) + (2 x 102) + (0 x 101) + (0 x 100)
Alternatively, since the product of 0 and any integer is 0, the number can be written more concisely as:
1,001,200 = (1 x 106) + (1 x 103) + (2 x 102)
Negative integers are represented in the same way, except with a negative sign. For example, the negative integer -137 is given as:
-137 = -[(1 x 102) + (3 x 101) + (7 x 100)]
Floating point and fractional numbers in the base-10 system are represented by a combination of positive and negative powers of 10, or, alternatively, powers of 1/10 = 0.1. Therefore,
10-1 = 1/10 = (1/10)1 = 0.1
10-2 = 1/100 = (1/10)2 = 0.01
10-3 = 1/1000 = (1/10)3 = 0.001
In general, if n is a positive integer, then 10–n = (1/10)n = 1 / (1 with n zeros).
For example, the base-10 floating point number 0.8246 is represented as:
0.8246 = (8 x 10-1) + (2 x 10-2) + (4 x 10-3) + (6 x 10-4)
The base-10 floating point number 723.0300519 is represented with both positive and negative powers of two:
723.0300519 = (7 x 102) + (2 x 101) + (3 x 100) + (0 x 10-1) + (3 x 10-2) + (0 x 10-3) + (0 x 10-4) + (5 x 10-5) + (1 x 10-6) + (9 x 10-7)
Alternatively, since the product of 0 and 10–n = (1/10)n is 0, the number can be written as:
723.0300519 = (7 x 102) + (2 x 101) + (3 x 100) + (3 x 10-2) + (5 x 10-5) + (1 x 10-6) + (9 x 10-7)
It is important to note that a floating point or fractional number can be represented perfectly (without error) in the base-10 numbering system only if the number can be expressed as sums of powers of 10. The examples above demonstrate numbers that have a perfect base-10 representation. However, many numbers – in fact, an infinite number of them – cannot be so expressed. Recall that the common number 1/3 has a decimal representation of 0.3333… where the “3” repeats infinitely. This means that 1/3 can only be approximated in the base-10 system. That is,
1/3 = 0.3333… = (3 x 10-1) + (3 x 10-2) + (3 x 10-3) + (3 x 10-4) + … + (3 x 10–n) + …
Similarly, 1/6 is approximately 0.1666… in decimal, where the “6” repeats. Consequently,
1/6 = (1 x 10-1) + (6 x 10-2) + (6 x 10-3) + (6 x 10-4) + … + (6 x 10–n) + …
Also, recall that some fractional numbers are repeating fractions. For instance, 1/7 = 0.142857142857142857, in which the group “142857” is repeated indefinitely. That is,
1/7 = (1 x 10-1) + (4 x 10-2) + (2 x 10-3) + (8 x 10-4) + (5 x 10-5) + (7 x 10-6) + …
+ (1 x 10m-1) + (4 x 10m-2) + (2 x 10m-3) + (8 x 10m-4) + (5 x 10m-5) + (7 x 10m-6) + …
Here, m is a multiple of six, since the repeating group has six decimal places. If m = 0 (m = 0 x 6), then the first six decimal places of the numbers result. If m = 12 (m = 2 x 6), then the thirteenth (m – 1)th through the eighteenth (m – 6)th decimal places consist of the repeating group “142857”.
The examples given above are known as rational numbers, as they can be expressed as a ratio of two integers, or, in other words, in fractional form. The decimal number 723.0300519 used above is a mixed fraction, 723 300519/10000000. Many numbers, however, are irrational. That is, they cannot be written as the ratio, or fraction, or two integers. They do not have an infinitely repeating decimal value (such as the repeating “3” used to represent 1/3 in decimal) or group of decimal values (such as the repeating “142857” group used to represent 1/7 in decimal). There are an infinite number of such irrational numbers. Two of the most common irrational numbers are π (pi), used in trigonometry, and e (Euler’s constant), which is the basis for natural logarithms and for many other mathematical operations. Many trigonometric values are irrational. For example, the sine function of 10° is irrational: sin(10°) ≈ 0.17364817766693033, where “≈” means “approximately equal to”. Recall that p ≈ 3.14159. Euler’s constant, or e, is expressed as e ≈ 2.71828. Both these numbers are irrational, as they cannot be expressed as a ratio (fraction). The number π is sometimes approximated as the mixed fraction π ≈ 22/7 = 3.142857… with the repeating group “142857”, as discussed above. However, this approximation already differs from the true value of π in the third decimal place.
The binary number system, or base-2 values, use two digits: 0, 1. These digits are commonly known as binary digits, or bits. Consequently, a single bit can assume the value of either 0 or 1. Each place corresponds to a power of 2. For example, the binary number 1101 is expressed as:
10111 = (1 x 24) + (0 x 23) + (1 x 22) + (1 x 21) + (1 x 20)
If this number were to be expressed in the base-10 system, the powers of 2 would be calculated and multiplied by their corresponding factor. Therefore,
10111 = (1 x 24) + (0 x 23) + (1 x 22) + (1 x 21) + (1 x 20)
= (1 x 16) + (0 x 8) + (1 x 4) + (1 x 2) + (1 x 1)
= 16 + 0 + 4 + 2 + 1 = 23
For clarity, binary (base-2) numbers will have a subscript of 2, which will distinguish them from base-10 numbers. If further clarity, base-10 numbers can have a subscript of 10. However, it is generally understood that numbers without a subscript indicate base-10 numbers. Using the previous example:
1011110 = (1 x 104) + (0 x 103) + (1 x 102) + (1 x 101) + (1 x 100), read as ten-thousand one-hundred eleven.
101112, as calculated above, is 23. This can be written as 101112 = 2310.
The binary representation of numbers will be covered in more detail in the next section.