CMPT 120: Assignment 1


Part 1: Written - 25%

Answer the following questions in a text file named assign1.txt.

1. Convert these binary numbers into decimal assuming they are unsigned integers. Show your calculations.
a. 1001     9
b. 011011     27
c. 01011010     90
d. 10000000     128
2. Convert the same binary numbers into decimal assuming they are using signed magnitude representation. Show your calculations.

a. -1
b. 27
c. 90
d. 0


3. Convert these binary numbers into decimal assuming they are using two's complement representation. Show your calculations.

a. -7
b. 27
c. 90
d. -128


4. Name the data types that the following expressions evaluate to in Python.
a. 21.0 * 4 - 123    float
b. 5 + 23 / 17    int
c. "34" + "2"    string
d. (24 * 32) > (43 - 12)    Boolean



Part 2: Programming - 75%

A program to compute the last digit of a barcode

A solution



Chris Schmidt, last updated June 10, 2007