Chapter 1 Number Bases, Conversion and Operations

Reading Materials: Croft, A. and R. Davidson Foundation maths. (Harlow: Pearson, 2016) 6th edition. Chapter 14 Number Bases

1.1 Number Bases

Decimal System

The numbers that we commonly used are based on 10. For example: \[\begin{equation} \label{eq1} \begin{split} 253 & = 200 + 50 + 3 \\ & = 2(100) + 5(10) + 3 \\ & = 2(10^2)+ 5(10^1) + 3(10^0) \end{split} \end{equation}\]

Binary System

A binary system uses base 2, it only consist of 2 digits, 0 and 1. Numbers in base 2 are called binary digits or simply bits. Consider the binary number \(110101_2\). As the base is 2, this means that power of 2 essentially replace powers of 10. Let us convert it to base 10. \[\begin{equation} \label{eq2} \begin{split} 110101_2 & = 1(2^5)+1(2^4)+0(2^3)+1(2^2)+0(2^1)+1(2^0) \\ & = 1(32)+1(16)+0(8)+1(4)+0(2)+1(1) \\ & = 32+16+4+1 \\ & = 53_{10} \end{split} \end{equation}\]

Octal System

Octal numbers use 8 as a base. The eight digits used in the octal system are 0, 1, 2, 3, 4, 5, 6 and 7. Octal numbers use powers of 8, just as decimal numbers use powers of 10 and binary numbers use powers of 2. Example: \[\begin{equation} \label{eq3} \begin{split} 325_8 & = 3(8^2)+2(8^1)+5(8^0) \\ & = 3(64)+2(8)+5(1) \\ & = 192+16+5 \\ & = 213_{10} \end{split} \end{equation}\]

Hexadecimal System

Hexadecimal system use 16 as a base. The digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. Example: \[\begin{equation} \label{eq4} \begin{split} 93\text{A}_{16} & = 9(16^2)+3(16^1)+\text{A}(16^0) \\ & = 9(256)+3(16)+10(1) \\ & = 2304+48+10 \\ & = 2362_{10} \end{split} \end{equation}\]

1.2 Number Conversion

1.2.1 Converting from Decimal to Other Number Base

The no-brainer way is to divide the number by the base, the remainder would be the last digit of the new number base. Keep dividing the quotient until it is smaller than the number base. Let us convert \(253_{10}\) as example. \[\begin{equation} \label{eq5} \begin{split} 2{\overline{\smash{\big)}\,253\phantom{)}}} & = 126 \text{ with remainder }1\\ 2{\overline{\smash{\big)}\,126\phantom{)}}} & = 63 \text{ with remainder }0\\ 2{\overline{\smash{\big)}\,63\phantom{)}}} & = 31 \text{ with remainder }1\\ 2{\overline{\smash{\big)}\,31\phantom{)}}} & = 15 \text{ with remainder }1\\ 2{\overline{\smash{\big)}\,15\phantom{)}}} & = 7 \text{ with remainder }1\\ 2{\overline{\smash{\big)}\,7\phantom{)}}} & = 3 \text{ with remainder }1\\ 2{\overline{\smash{\big)}\,3\phantom{)}}} & = 1 \text{ with remainder }1\\ 2{\overline{\smash{\big)}\,1\phantom{)}}} & = 0 \text{ with remainder }1 \end{split} \end{equation}\] Thus, \(253_{10}\) is \(11111101_2\) in binary. We could do the same to other number bases. Another method is by listing the powers of the base, compare and subtract. Using the same number as example.

\(2^0 = 1\) \(2^1 = 2\) \(2^2 = 4\)
\(2^3 = 8\) \(2^4 = 16\) \(2^5 = 32\)
\(2^6 = 64\) \(2^7 = 128\) \(2^8 = 256\)

From here we compare the number that we are going to convert with the list: \[\begin{equation} \label{eq6} \begin{split} 253 - 1(128) & = 125 \\ 125 - 1(64) & = 61 \\ 61 - 1(32) & = 29 \\ 29 - 1(16) & = 13 \\ 13 - 1(8) & = 5 \\ 5 - 1(4) & = 1 \\ 1 - 0(2) & = 1\\ 1- 1(1) & = 0 \end{split} \end{equation}\] Thus, \(253_{10}\) is \(11111101_2\) in binary. Like the other method, we can also do this to convert to other number bases.

1.2.2 Conversion with Binary Number

Converting binary numbers to Octal or Hexadecimal and vice versa are very straightforward. It can be performed without converting to Decimal first. Let us use number \(11100110_2\) as example: \[\begin{equation} \label{eq7} \begin{split} \underbrace{11}_\text{3}\underbrace{100}_\text{4}\underbrace{110}_\text{6} & = 346_8\\ \underbrace{1110}_\text{E}\underbrace{0110}_\text{6} & = \text{E}6_{16} \end{split} \end{equation}\]

Converting non-integer number might look counterintuitive and intimidating. It is actually rather simple. Let us convert \(17.375_{10}\) to binary. \[\begin{split} 17.375 & = 10 + 7 + 0.3+0.07+0.005 \\ & = 1(10^1) + 7(10^0) + 3(10^{-1}) + 7(10^{-2})+5(10^{-3}) \end{split}\] Converting to binary, \(17_{10} = 10001_2\). But how about the decimal point? We multiply them by two until we are left with whole number \[\begin{equation} \label{eq8} \begin{split} 0.375 \times 2 = 0.75 = 0+0.75 & \text{ we have 0 at power }-1\\ 0.75 \times 2 = 1.5 = 1+0.5 & \text{ we have 1 at power }-2\\ 0.5 \times 2 = 1.0 = 1 & \text{ we have 1 at power }-3 \end{split} \end{equation}\] Thus, \(17.375_{10} = 10001.011_2\) The reverse is much simpler. \[\begin{equation} \label{eq9} \begin{split} 1101.101_2 & = 1(2^3)+1(2^2)+0(2^1)+1(2^0)+1(2^{-1})+0(2^{-2})+1(2^{-3}) \\ & = 1(8)+1(4)+0(2)+1(1)+1(0.5)+0(0.25)+1(0.125) \\ & = 8 + 4 + 1+ 0.5+0.125 \\ & = 13.625_{10} \end{split} \end{equation}\]

1.2.3 Operations with Binary Number

Addition

Addition is rather straightforward, just like with decimal numbers. Here we use \(11001001_2\) and \(11111111_2\) as example. In decimal they are 201 and 255 respectively. \[\begin{equation}\label{eq10} \begin{array}{B3} \overset{1}0 & \overset{1}1\overset{1}1\overset{1}0\overset{1}0 & \overset{1}1\overset{1}0\overset{1}01 \\ {} + 0 & 1111 & 1111\\ \hline 1 & 1100 & 1000\\ \end{array} \end{equation}\] \[\begin{equation} \label{eq11} \underbrace{11001001}_\text{201}+\underbrace{11111111}_\text{255} = \underbrace{1 1100 1000}_\text{456} \end{equation}\]

Subtraction

Likewise for subtraction, between \(111 0011_2\) and \(101 0010_2\) \[\begin{equation}\label{eq12} \begin{array}{B3} 1 1 1 & 0 0 11\\ {} - 101 & 0010\\ \hline 010 & 0001 \\ \end{array} \end{equation}\] \[\begin{equation} \label{eq13} \underbrace{1110011}_\text{115}-\underbrace{1010010}_\text{82} = \underbrace{100001}_\text{33} \end{equation}\]

Multiplication

Multiplication is essentially addition done multiple times. Let us have multiplication of \(1100_2\) and \(1111_2\). I would skip the carry so it wouldn’t look too cramped. \[\begin{equation}\label{eq14} \begin{array}{c} \phantom{\times9999}1100\\ \underline{\times\phantom{9999}1111}\\ \phantom{\times9999}1100\\ \phantom{\times999}1100\phantom9\\ \phantom{\times99}1100\phantom{99}\\ \underline{\phantom{\times9}1100\phantom{999}}\\ \phantom\times10110100 \end{array} \end{equation}\] \[\begin{equation} \label{eq15} \underbrace{1100}_\text{12}\times\underbrace{1111}_\text{15} = \underbrace{10110100}_\text{180} \end{equation}\]

Division

Division is perhaps the one that feels the most unnatural and most likely to cause mistakes. Let us do this with \(11100110_2\) divided with \(110_2\) as example. \[\begin{equation}\label{eq16} \begin{array}{r} 100110\phantom{)} \\ 110{\overline{\smash{\big)}\,11100110\phantom{)}}}\\ \underline{-~\phantom{(}110\phantom{99999)}}\\ \phantom{\times{99}}10\phantom{9999)}\\ \underline{-~\phantom{()}0\phantom{9999)}}\\ \phantom{\times{99}}100\phantom{999)}\\ \underline{-~\phantom{()}0\phantom{999)}}\\ \phantom{\times{99}}1001\phantom{99)}\\ \underline{-~\phantom{()}110\phantom{99)}}\\ \phantom{\times{999}}111\phantom{9)}\\ \underline{-~\phantom{()}110\phantom{9)}}\\ \phantom{\times{9999}}10\phantom{)}\\ \underline{-~\phantom{()}0\phantom{)}}\\ 10\phantom{)} \end{array} \end{equation}\]

\[\begin{equation} \label{eq17} \underbrace{11100110}_\text{230}\div\underbrace{110}_\text{12} = \underbrace{100110}_\text{38} \text{ with remainder }\underbrace{10}_\text{2} \end{equation}\]