Section 2.3 Mathematical Equivalence of Binary and Decimal
¶We have seen in the previous section that binary digits are the natural way to show the states of switches within the computer and that hexadecimal is a convenient way to show the states of up to four switches with only one character. Now we explore some of the mathematical properties of the binary number system and show that it is numerically equivalent to the more familiar decimal (base 10) number system. Showing the mathematical equivalence of the hexadecimal and decimal number systems is left as an exercise for you following this section.
By convention, we use a positional notation when writing numbers. For example, in the decimal number system, the integer \(123\) is taken to mean
or
The rightmost digit (3 in Equations (2.3.1) and (2.3.2)) is the least significant digit because it “counts” the least in the total value of this number. The leftmost digit (1 in this example) is the most significant digit because it “counts” the most in the total value of this number.
The base or radix of the decimal number system is ten. There are ten symbols for representing the digits: 0, 1,…, 9. Moving a digit one place to the left increases its value by a factor of ten, and moving it one place to the right decreases its value by a factor of ten. The positional notation generalizes to any radix, \(r\text{:}\)
where there are \(n\) digits in the number and each \(d_{i} = 0, 1, \ldots, r1\text{.}\) The radix in the binary number system is 2, so there are only two symbols for representing the digits: \(d_{i} = \binary{0}, \binary{1}\text{.}\) We can specialize Equation (2.3.3) for the binary number system as
where there are \(n\) digits in the number and each \(d_{i} = \binary{0}, \binary{1}\text{.}\)
Although we are considering only integers at this point, Equation (2.3.3) does, of course, generalize to fractional values. Simply continue the exponents of the radix, \(r\text{,}\) on to negative values, that is, \(r^{n1}, r^{n2},\ldots, r^{1}, r^{0}, r^{1}, r^{2},\ldots\) . This will be covered in detail in Chapter 16.
It is very simple to convert from binary to decimal:
Algorithm 2.3.1. Binary to Unsigned Decimal.
Compute powers of 2, multiply by the respective bit, and add.
\(result = 0\)

For \(i = 0, \cdots, (n1)\)
\(result = result + d_{i} * 2^{i}\)