A document from MCS 260 Fall 2021, instructor Emily Dumas. You can also get the notebook file.

# MCS 260 Fall 2021 Homework 1 Solutions¶

• Course instructor: Emily Dumas

## 3. Decimal to binary table¶

Recall from Lecture 1 that one way to convert a number to binary is to make a 3-column table where each row contains values x, x//2, and x%2, and where the next row begins with the middle entry of the previous row. The table ends when the row 1 0 1 is obtained. Then, reading the last column of the table from bottom to top gives the binary digits of the number at the start of the table.

In Visual Studio Code (or another text editor) you can make a table like this by creating a new text file and typing the column headings, rows, and the final result into the editor window. For example, if you were asked to convert 53 to binary, the contents of this text file might be:

x   x//2  x%2
53  26    1
26  13    0
13  6     1
6   3     0
3   1     1
1   0     1

Therefore, 53 in binary is 0b110101. Create a text file (named e.g. binaryconversion.txt) in this format showing the process to convert 61 to binary. Make sure to include the line stating the conclusion ("Therefore, 61 in binary is...").

Note that you must not create this as a document in Word, WordPad, Pages, or similar word processing applications. The file you upload needs to be pure text, like the .py files for the Python programs we'll write in future assignments.

### Solution¶

The contents of binaryconversion.txt might be:

x   x//2  x%2
61  30    1
30  15    0
15  7     1
7   3     1
3   1     1
1   0     1

Therefore, 61 in binary is 0b111101

## 4. Hex to binary¶

Convert the hexadecimal number 0x84C to binary, and enter the result in python format (beginning with 0b) below. To allow automated checking of your answer, do not use any digit separators (i.e. no underscore characters _).

In [ ]:
0b100001001100