1.04: Fixed-Point Binary Representation of Numbers
- Page ID
- 126383
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)Lesson 1: Introduction to Binary Representation of Numbers
Learning Objectives
After successful completion of this lesson, you should be able to:
1) enumerate different bases of number systems and be able to convert base-2 numbers to base-10 numbers.
Introduction
In everyday life, we use a number system that has a base of \(10\) (decimal system). When a number is written in this system, we can quickly decipher it as we see such numbers throughout the day.
For example, look at the number \(257.36\). Each digit in \(257.36\) has a value of \(0\) through \(9\) and has a place value where the position of the number with respect to the decimal point determines its value. Each position in the decimal number corresponds to an integer exponent of \(10\). In the number \(257.36\), the \(2\) is in the place value of hundred, that is \(10^{2}\), while the \(3\) is in the place of one-tenths, that is, \(10^{- 1}\). The number \(257.36\) can be written as
\[\begin{split} 257.36 &= 2 \times 10^{2} +5 \times 10^{1} + 7 \times 10^{0} + 3 \times 10^{- 1} + 6 \times 10^{- 2}\\ &= 200 + 50 + 7 + 0.3 + 0.06\\ &= 257.36\end{split} \nonumber\]
In a binary system, we have a similar system as the base-\(10\), but the only difference is that the base is made of only two digits, \(0\) and \(1\). So it is a base-\(2\) system. A number like \((1011.0011)\) in base-\(2\) represents an equivalent decimal number as
\[\begin{split} (1011.0011)_{2} &= \begin{pmatrix} \left( 1 \times 2^{3} + 0 \times 2^{2} + 1 \times 2^{1} + 1 \times 2^{0} \right) \\ + (0 \times 2^{- 1} + 0 \times 2^{- 2} + 1 \times 2^{- 3} + 1 \times 2^{- 4}) \\ \end{pmatrix}_{10}\\ &= \begin{pmatrix} \left( 1 \times 8 + 0 \times 4 + 1 \times 2 + 1 \times 1 \right) \\ + (0 \times 0.5 + 0 \times 0.25 + 1 \times 0.125 + 1 \times 0.0625) \\ \end{pmatrix}_{10}\\ &= \left( 8 + 0 + 2 + 1 + 0 + 0 + 0.125 + 0.0625 \right)_{10}\\ &= \left( 11.1875 \right)_{10}\end{split} \nonumber\]
Note the dot (.) that separates the integer and fractional part in the binary representation or any other representation is called the radix point.
Find the equivalent of \(\left( 1101 \right)_{2}\) in base-\(10\).
Solution
\[\begin{split} (1101)_{2} &= \left( 1 \times 2^{3} + 1 \times 2^{2} + 0 \times 2^{1} + 1 \times 2^{0} \right)_{10}\\ &= \left( 1 \times 8 + 1 \times 4 + 0 \times 2 + 1 \times 1 \right)_{10}\\ &= {\left( 8 + 4 + 0 + 1 \right)}_{10}\\ &= \left( 13 \right)_{10}\end{split} \nonumber\]
Find the equivalent of \(\left( 0.1101 \right)_{2}\) in base-\(10\).
Solution
\[\begin{split} (0.1101)_{2} &= \left( 1 \times 2^{- 1} + 1 \times 2^{- 2} + 0 \times 2^{- 3} + 1 \times 2^{- 4} \right)_{10}\\ &= \left( 0.5 + 0.25 + 0 + 0.0625 \right)_{10}\\ &= \left( 0.8125 \right)_{10}\end{split} \nonumber\]
Find the equivalent of \(\left( 1101.1101 \right)_{2}\) in base-\(10\).
Solution
From Example \(\PageIndex{1.1}\),
\[(1101)_{2} = \left( 13 \right)_{10} \nonumber\]
From Example \(\PageIndex{1.2}\),
\[(0.1101)_{2} = \left( 0.8125 \right)_{10} \nonumber\]
Hence
\[(1101.1101)_{2} = \left( 13.8125 \right)_{10} \nonumber\]
Audiovisual Lectures
Title: Binary Representation of Numbers
Summary: Learn about the binary representation of numbers - how to convert a base-2 number to a base-10 number.
Lesson 2: Fixed-Point Binary Representation of Numbers
Learning Objectives
After successful completion of this lesson, you should be able to:
1) convert a base-10 number to a base-2 number in a fixed format.
Introduction
To understand the binary system, we need to convert binary numbers to decimal numbers and vice-versa. We have already seen an example of how binary numbers can be converted to decimal numbers. Let us see how we can convert a decimal number to a binary number. For example, take the decimal number \(11.1875\).
First, look at the integer part: \(11\).
Divide \(11\) by \(2\). This division gives a quotient of \(5\) and a remainder of \(1\). Since the remainder is \(1\), \(a_{0} = 1\).
Divide the quotient \(5\) by \(2\). This division gives a quotient of \(2\) and a remainder of \(1\). Since the remainder is \(1\), \(a_{1} = 1\).
Divide the quotient \(2\) by \(2\). This division gives a quotient of \(1\) and a remainder of \(0\). Since the remainder is \(0\), \(a_{2} = 0\).
Divide the quotient \(1\) by \(2\). This division gives a quotient of \(0\) and a remainder of \(1\). Since the remainder is \(1\), \(a_{3} = 1\).
Since the quotient now is \(0\), the process is stopped. The above steps are summarized in Table \(\PageIndex{2.1}\).
Quotient | Remainder | |
---|---|---|
\(11/2\) | \(5\) | \(1 = a_{0}\) |
\(5/2\) | \(2\) | \(1 = a_{1}\) |
\(2/2\) | \(1\) | \(0 = a_{2}\) |
\(1/2\) | \(0\) | \(1 = a_{3}\) |
Hence
\[\begin{split} (11)_{10} &= (a_{3}a_{2}a_{1}a_{0})_{2}\\ &= (1011)_{2}\end{split} \nonumber\]
For any integer, the algorithm for finding the binary equivalent is given in the flow chart in Figure \(\PageIndex{2.1}\).
Now let us look at the decimal part, that is, \(0.1875\).
Multiply \(0.1875\) by \(2\). This multiplication gives \(0.375\). The number before the decimal is \(0,\) and the number after the decimal is \(0.375\). Since the number before the decimal is \(0\), \(a_{- 1} = 0\).
Multiply the number after the decimal, that is, \(0.375\) by \(2\). This multiplication gives \(0.75\). The number before the decimal is \(0,\) and the number after the decimal is \(0.75\). Since the number before the decimal is \(0\), \(a_{- 2} = 0\).
Multiply the number after the decimal, that is, \(0.75\) by \(2\). This multiplication gives \(1.5\). The number before the decimal is \(1,\) and the number after the decimal is \(0.5\). Since the number before the decimal is \(1\), \(a_{- 3} = 1\).
Multiply the number after the decimal, that is, \(0.5\) by \(2\). This multiplication gives \(1.0\). The number before the decimal is \(1,\) and the number after the decimal is \(0\). Since the number before the decimal is \(1\), \(a_{- 4} = 1.\)
Since the number after the decimal is \(0\), the conversion is complete. The above steps are summarized in Table \(\PageIndex{2.2}\).
Number | Number after decimal | Number before decimal | |
---|---|---|---|
\(0.1875\times2\) | \(0.375\) | \(0.375\) | \(0 = a_{- 1}\) |
\(0.375\times2\) | \(0.75\) | \(0.75\) | \(0 = a_{- 2}\) |
\(0.75\times2\) | \(1.5\) | \(0.5\) | \(1 = a_{- 3}\) |
\(0.5\times2\) | \(1.0\) | \(0.0\) | \(1 = a_{- 4}\) |
Hence
\[\begin{split} (0.1875)_{10} &= (a_{- 1}a_{- 2}a_{- 3}a_{- 4})_{2}\\ &= (0.0011)_{2}\end{split} \nonumber\]
Having calculated
\[(11)_{10} = (1011)_{2} \nonumber\]
and
\[(0.1875)_{10} = (0.0011)_{2}, \nonumber\]
we have
\[(11.1875)_{10} = (1011.0011)_{2}. \nonumber\]
In the above example, when we were converting the fractional part of the number, we were left with \(0\) after the decimal number and used that as a place to stop. In many cases, we are never left with a \(0\) after the decimal number. For example, finding the binary equivalent of \(0.3\) is summarized in Table \(\PageIndex{2.3}\).
Number | Number after decimal | Number before decimal | |
---|---|---|---|
\(0.3\times2\) | \(0.6\) | \(0.6\) | \(0 = a_{- 1}\) |
\(0.6\times2\) | \(1.2\) | \(0.2\) | \(1 = a_{- 2}\) |
\(0.2\times2\) | \(0.4\) | \(0.4\) | \(0 = a_{- 3}\) |
\(0.4\times2\) | \(0.8\) | \(0.8\) | \(0 = a_{- 4}\) |
\(0.8\times2\) | \(1.6\) | \(0.6\) | \(1 = a_{- 5}\) |
As you can see, the process will never end. In this case, the number can only be approximated in binary format, that is,
\[\begin{split} (0.3)_{10} &\approx (a_{- 1}a_{- 2}a_{- 3}a_{- 4}a_{- 5})_{2}\\ &= (0.01001)_{2}\end{split} \nonumber\]
Convert \((13.875)_{10}\) to base \(2\).
Solution
For \((13)_{10}\), conversion to binary format is shown in Table \(\PageIndex{2.4}\).
Quotient | Remainder | |
---|---|---|
\(13/2\) | \(6\) | \(1 = a_{0}\) |
\(6/2\) | \(3\) | \(0 = a_{1}\) |
\(3/2\) | \(1\) | \(1 = a_{2}\) |
\(1/2\) | \(0\) | \(1 = a_{3}\) |
So
\[(13)_{10} = (1101)_{2}. \nonumber\]
Conversion of \((0.875)_{10}\) to binary format is shown in Table \(\PageIndex{2.5}\).
Number | Number after decimal | Number before decimal | |
---|---|---|---|
\(0.875\times2\) | \(1.75\) | \(0.75\) | \(1 = a_{- 1}\) |
\(0.75\times 2\) | \(1.5\) | \(0.5\) | \(1 = a_{- 2}\) |
\(0.5\times2\) | \(1.0\) | \(0.0\) | \(1 = a_{- 3}\) |
So
\[(0.875)_{10} = (0.111)_{2} \nonumber\]
Hence
\[(13.875)_{10} = (1101.111)_{2} \nonumber\]
Audiovisual Lectures
Title: Base 10 to Base 2 Conversion
Summary: See a method to convert a base-10 to a base-2 number.
But what is the mathematics behinds this process of converting a decimal number to binary format?
Let \(z\) be the decimal number written as
\[z = x.y \nonumber\]
where
\(x\) is the integer part, and \(y\) is the fractional part.
We want to find the binary equivalent of \(x\). So, we can write
\[x = a_{n}2^{n} + a_{n - 1}2^{n - 1} + ... + a_{0}2^{0} \nonumber\]
If we can now find \(a_{0},...,a_{n}\)in the above equation, then
\[(x)_{10} = (a_{n}a_{n - 1}\text{...}a_{0})_{2} \nonumber\]
We now want to find the binary equivalent of \(y\). So, we can write
\[y = b_{- 1}2^{- 1} + b_{- 2}2^{- 2} + ... + b_{- m}2^{- m} \nonumber\]
If we can now find \(b_{- 1},...,b_{- m}\)in the above equation, then
\[(y)_{10} = (b_{- 1}b_{- 2}\text{...}b_{- m})_{2} \nonumber\]
Let us look at this using the same example as before.
Convert \((11.1875)_{10}\) to base \(2\).
Solution
To convert \((11)_{10}\) to base \(2\), what is the highest power of \(2\) that is part of \(11\). That power is \(3\), as \(2^{3} = 8\) to give
\[11 = 2^{3} + 3 \nonumber\]
What is the highest power of \(2\) that is part of \(3\)? That power is \(1\), as \(2^{1} = 2\) to give
\[3 = 2^{1} + 1 \nonumber\]
So
\[\begin{split} 11 &= 2^{3} + 3\\ &= 2^{3} + 2^{1} + 1\end{split} \nonumber\]
What is the highest power of \(2\) that is part of \(1\)? That power is \(0\), as \(2^{0} = 1\), to give
\[1 = 2^{0} \nonumber\]
Hence
\[\begin{split} (11)_{10} &= 2^{3} + 2^{1} + 1\\ &= 2^{3} + 2^{1} + 2^{0}\\ &= 1 \times 2^{3} + 0 \times 2^{2} + 1 \times 2^{1} + 1 \times 2^{0}\\ &= (1011)_{2}\end{split} \nonumber\]
To convert \((0.1875)_{10}\) to base \(2\), we proceed as follows. What is the smallest negative power of \(2\) that is less than or equal to \(0.1875\)? That power is \(- 3\) as \(2^{- 3} = 0.125\).
So
\[0.1875 = 2^{- 3} + 0.0625 \nonumber\]
What is the next smallest negative power of \(2\) that is less than or equal to \(0.0625\)? That power is \(- 4\) as \(2^{- 4} = 0.0625\).
So
\[0.1875 = 2^{- 3} + 2^{- 4} \nonumber\]
Hence
\[\begin{split} (0.1875)_{10} &= 2^{- 3} + 0.0625 = 2^{- 3} + 2^{- 4}\\ &= 0 \times 2^{- 1} + 0 \times 2^{- 2} + 1 \times 2^{- 3} + 1 \times 2^{- 4}\\ &= (0.0011)_{2}\end{split} \nonumber\]
Since
\[(11)_{10} = (1011)_{2} \nonumber\]
and
\[(0.1875)_{10} = (0.0011)_{2} \nonumber\]
we get
\[(11.1875)_{10} = (1011.0011)_{2} \nonumber\]
One can show the above process algebraically for any general number, but it is out-of-scope for this course.
Lesson 3: Writing a Fixed-Point Binary Number in Given Word Length
Learning Objectives
After successful completion of this lesson, you should be able to:
1) write a base-2 number in a given word length.
Introduction
A fixed-point binary number may need to be stored in a given number of bits called the word length. Some of the bits in the word would be used for the integer part and the rest of them for the fractional part. In addition, a bit would also be used to signify the sign of the number. This is best illustrated through an example.
Given that a fixed-point positive binary number is stored in eight bits word length, where the first six bits are used for the integer part and the next two for the fractional part, how would the \((13.875)_{10}\) be stored? We are given that \((13.875)_{10} = (1101.111)_{2}\).
Solution
Since there are six bits for the integer part and two for the fractional part, we will first rewrite the number as
\[\begin{split} (13.875)_{10} &= (1101.111)_{2}\\ &\approx (001101.11)_{2}\end{split}\]
This occupies the right number of bits for the integer part (\(6 \ \text{bits}\)) and the fractional part (\(2\ \text{bits}\)). We write \(1101\) as \(001101\) to occupy the \(6\) places without changing it value. We approximate the fractional part \(.111\) to \(.11\) as we have only \(2\) bits for it.
Multiple Choice Test
(1). \(\left( 25 \right)_{10} = \left( ? \right)_{2}\)
(A) \(100110\)
(B) \(10011\)
(C) \(11001\)
(D) \(110010\)
(2). \(\left( 1101 \right)_{2} = \left( ? \right)_{10}\)
(A) \(3\)
(B) \(13\)
(C) \(15\)
(D) \(26\)
(3). \(\left( 25.375 \right)_{10} = \left( ?.? \right)_{2}\)
(A) \(100110.011\)
(B) \(11001.011\)
(C) \(10011.0011\)
(D) \(10011.110\)
(4). Representing \(\sqrt{2}\) in a fixed-point binary register with \(2\) bits for the integer part and \(3\) bits for the fractional part gives a round-off error of most nearly
(A) \(-0.085709\)
(B) \(0.0392\)
(C) \(0.1642\)
(D) \(0.2892\)
(5). An engineer working for the Department of Defense is writing a program that transfers non-negative real numbers to integer format. To avoid overflow problems, the maximum non-negative integer that can be represented in a \(5\)-bit binary integer word is
(A) \(16\)
(B) \(31\)
(C) \(63\)
(D) \(64\)
(6). For a numerically controlled machine, integers need to be stored in a memory location. The minimum number of bits needed for an integer binary word to represent all integers between \(0\) and \(1024\) is
(A) \(8\)
(B) \(9\)
(C) \(10\)
(D) \(11\)
For complete solution, go to
http://nm.mathforcollege.com/mcquizzes/01aae/quiz_01aae_binaryrepresentation_answers.pdf
Problem Set
(1). Convert the following.
a) \((19)_{10} = (?)_{2}\)
b) \((75)_{10} = (?)_{2}\)
- Answer
-
\(a)\ 100111\ \ b)\ 1001011\)
(2). Convert the following.
a) \((110111)_{2} = (?)_{10}\)
b) \((11001)_{2} = (?)_{10}\)
- Answer
-
\(a)\ 55\ \ b)\ 25\)
(3). Convert the following.
a) \((0.375)_{10} = (?)_{2}\)
b) \((0.075)_{10} = (?)_{2}\)
- Answer
-
\(a)\ 0.011\ \ b)\ 0.000100110011...\)
(4). Convert the following.
a) \((0.110001)_{2} = (0.?)_{10}\)
b) \((0.0111)_{2} = (0.?)_{10}\)
- Answer
-
\(a)\ 0.765625\ \ b)\ 0.4375\)
(5). Convert the following.
a) \((19.375)_{10} = (?.?)_{2}\)
b) \((75.075)_{10} = (?.?)_{2}\)
- Answer
-
\(a)\ 10011.011\ \ b)\ 1001011.00010011.......\)
(6). Convert the following.
a) \((110111.110001)_{2} = (?.?)_{10}\)
b) \((11001.0111)_{2} = (?.?)_{10}\)
- Answer
-
\(a)\ 55.765625\ \ b)\ 25.4375\)