Converting Decimal Numbers to Binary Numbers

# Converting Decimal Numbers to Binary Numbers

We have just looked at Converting Binary Numbers to Decimal Numbers. Doing the reverse process, that is, converting a decimal number into a binary number requires more involvement. Let $x \in \mathbb{R}$. Then $x$ can be split up into an integer and fractional part. For example, the number $5.1242$ can be split up as $5 + 0.1242$. The number $11.25$ can be split up at $11 + 0.25$. More specifically, we will take the number $x$ and split it up as $x = x_I + x_F$ where $x_I = \left \lfloor x \right \rfloor$ and $0 ≤ x_F = x - \left \lfloor x \right \rfloor < 1$. The notation $\left \lfloor x \right \rfloor$ represents the floor function. For any $x \in \mathbb{R}$, $\left \lfloor x \right \rfloor$ is defined to be the largest integer less than or equal to $x$.

To convert the integer $(x_I)_{10} \in \mathbb{Z}$ into binary, we will utilize the following conversion algorithm.

Step 1 Take $x_I$ and divide it by $2$. Let $Q_1$ be the quotient and $a_0$ be the remainder of this division step. Take $Q_1$ and divide it by $2$. Let $Q_2$ be the quotient and $a_1$ be the remainder of this division step. Take $Q_{j-1}$ and divide it by $2$. Let $Q_j$ be the quotient and $a_{j-1}$ be the remainder of this division step. Eventually the process described above will terminate at some step $n$ where the quotient $Q_n = 0$. Then we will have $(x_I)_{10} = (a_na_{n-1}...a_1a_0)_{2}$.

Let's look at an example of applying the conversion algorithm above. Consider the integer $67$.

Step 1 Take $67$ and divide it by $2$. We get that $\frac{67}{2}$ has quotient $33$ with remainder $1$. Let $a_0 = 1$. Take $33$ and divide it by $2$. We get that $\frac{33}{2}$ has quotient $16$ remainder $1$. Let $a_1 = 1$. Take $16$ and divide it by $2$. We get that $\frac{16}{2}$ has quotient $8$ with remainder $0$. Let $a_2 = 0$. Take $8$ and divide it by $2$. We get that $\frac{8}{2}$ has quotient $4$ with remainder $0$. Let $a_3 = 0$. Take $4$ and divide it by $2$. We get that $\frac{4}{2}$ has quotient $2$ with remainder $0$. Let $a_4 = 0$. Take $2$ and divide it by $2$. We get that $\frac{2}{2}$ has quotient $1$ with remainder $0$. Let $a_5 = 0$. Take $1$ and divide it by $2$. We get that $\frac{1}{2}$ has quotient $0$ with remainder $1$. Let $a_6 = 1$. Since the quotient has become $0$, we terminate this algorithm.

Therefore $(67)_{10} = a_6a_5a_4a_3a_2a_1a_0 = (1000011)_{2}$.

Now we will look at the algorithm for converting $0 ≤ x_F < 1$ into binary.

Step 1 Take $x_F$ and multiply it by $2$. Let $I_1 = a_{-1}$ be the integer part and $F_1$ be the fractional part of this product step. Take $F_1$ and multiply it by $2$. Let $I_2 = a_{-2}$ be the integer part and $F_2$ be the fractional part of this product step. Take $F_{j-1}$ and multiply it by $2$. Let $I_j = a_{-j}$ be the integer part and $F_j$ be the fractional part of this product step. If the process described above will terminate at some step $m$ where the fractional part $F_m = 0$. Then we will have $(x_F)_{10} = (0.a_{-1}a_{-2}...a_{-m+1}a_{-m})_{2}$. Note that this process need not terminate though.

Let's look at an example of applying the conversion algorithm above. Consider the number $(0.90625)_{10}$.

Step 1 Take $0.90625$ and multiply it by $2$. We get that $0.90625 \cdot 2 = 1.8125$ so let $1 = a_{-1}$ and let $0.8125$ be the fractional part. Take $0.8125$ and multiply it by $2$. We get that $0.8125 \cdot 2 = 1.625$ so let $1 = a_{-2}$ and let $0.625$ be the fractional part. Take $0.625$ and multiply it by $2$. We get that $0.625 \cdot 2 = 1.25$ so let $1 = a_{-3}$ and let $0.25$ be the fractional part. Take $0.25$ and multiply it by $2$. We get that $0.25 \cdot 2 = 0.5$ so let $0 = a_{-4}$ and let $0.5$ be the fractional part. Take $0.5$ and multiply it by $2$. We get that $0.5 \cdot 2 = 1$ so let $0 = a_{-5}$ and let $0$ be the fractional part. Since the fractional part has become $0$, we terminate this algorithm.

Therefore $(0.90625)_{10} = a_{-1}a_{-2}a_{-3}a_{-4}a_{-5}a_{-6}= (0.11101)_{2}$.

If we wanted to convert the number $(67.90625)_{10}$ into binary, then we would split the number into its integer part and fractional part and apply both algorithms to get that $(67.90625)_{10} = (1000011.11101)_{2}$.