Skip to main content

Unit 1.1 Launch

In this note, we illustrate how fundamental knowledge taught in a typical logic course elevates programming from an art to a science. The target audience are learners who have not seen (much) formal logic. Some may have been programming is one or more language for a while. Others may be just starting their journey towards becoming computer scientists. For this reason, we do not expect much in terms of a background. We hope to motivate why acquiring a strong background in logic is important for those who want to become computer scientists. With that, let's dive right in!

Exercise 1.1.

Convert the binary number number \(1 0 1 1 \) into a decimal number.

Solution

Let \(y \) represent the desired decimal number. then

\begin{equation*} y = (1) + \begin{array}[t]{c} \underbrace{ (1) \times 2 } \\ 2 \end{array} + \begin{array}[t]{c} \underbrace{ (0) \times 2^2 } \\ 0 \end{array} + \begin{array}[t]{c} \underbrace{ (1) \times 2^3 } \\ 8 \end{array} = 11. \end{equation*}
Exercise 1.2.

Given a binary number with \(n \) digits represented as

\begin{equation*} a_{n-1} a_{n-2} \cdots a_2 a_1 a_0, \end{equation*}

where \(a_0 \) is the least significant digit, what is the formula for computing the equivalent decimal number?

Hint

In our example in Exercise 1.1, \(n = 4 \) and \(1011 \) is represented by

\begin{equation*} a_0 = 1, a_1 = 1, a_2 = 0, a_3 = 1. \end{equation*}
Solution

The decimal number, \(y \text{,}\) is given by

\begin{equation*} y = a_0 + a_1 \times 2 + a_2 \times 2^2 + \cdots + a_{n-2} \times 2^{n-2} + a_{n-1} \times 2^{n-1}. \end{equation*}

Another way of talking about a binary number is that it is given in base 2.

Exercise 1.3.

Convert the base 3 number \(2 0 1 2 \) into a decimal number.

Solution

Let \(y \) represent the desired decimal number. then

\begin{equation*} y = (2) + \begin{array}[t]{c} \underbrace{ (1) \times 3 } \\ 3 \end{array} + \begin{array}[t]{c} \underbrace{ (0) \times 3^2 } \\ 0 \end{array} + \begin{array}[t]{c} \underbrace{ (2) \times 3^3 } \\ 54 \end{array} = 59. \end{equation*}
Exercise 1.4.

Given a base 3 number with \(n \) digits represented as

\begin{equation*} a_{n-1} a_{n-2} \cdots a_2 a_1 a_0, \end{equation*}

where \(a_0 \) is the least significant digit, what is the formula for computing the equivalent decimal number?

Solution

The decimal number, \(y \text{,}\) is given by

\begin{equation*} y = a_0 + a_1 \times 3 + a_2 \times 3^2 + \cdots + a_{n-2} \times 3^{n-2} + a_{n-1} \times 3^{n-1}. \end{equation*}
Exercise 1.5.

Let \(x \) be an integer greater than \(1 \text{.}\) Given a base \(x \) number with \(n \) digits represented as

\begin{equation*} a_{n-1} a_{n-2} \cdots a_2 a_1 a_0, \end{equation*}

where \(a_0 \) is the least significant digit, what is the formula for computing the equivalent decimal number?

Solution

The decimal number, \(y \text{,}\) is given by

\begin{equation*} y = a_0 + a_1 \times x + a_2 \times x^2 + \cdots + a_{n-2} \times x^{n-2} + a_{n-1} \times x^{n-1}. \end{equation*}