CSCI 101: Intro to Computer Science

Assignment 5.     Due: Mon, Jul 7

Solutions will be posted on Wed, Jul 9

Please save your work in a single text file hw5.txt and upload it on Canvas before midnight of the day above.

  1. (3x5=15 points)   Convert the following binary numbers to decimal:
    1. 1111
    2. 101001
    3. 110011

  2. (3x5=15 points)   Convert the following decimal numbers to binary:
    1. 45
    2. 258
    3. 1111

  3. (2x5=10 points)  
    1. Convert the following HEX number to decimal: CAB
    2. Write your first name in ASCII code.

  4. (2x10=20 points)   Write PIPPIN programs to perform the following tasks:
    1. Swap the contents of cells 5 and 6
    2. Compute the absolute value |X| of a number stored in a cell X. The absolute value is defined as follows:
      if X > 0, then |X| = X
      if X < 0, then |X| = -X
      
      For example, 5 > 0, so |5| = 5.
      On the other hand, -3 < 0, so |-3| = -(-3) = +3.

  5. (20 points)   Write a PIPPIN program to compute X=(A+B)*(C+D), assuming A,B,C,D, and X are stored in cells 100, 101, 102, 103, and 104 respectively.

  6. (2x10=20 points)   Draw the parse trees for the following algebraic expressions:
    1. ((x + y) + z) * (x + z)
    2. 1 + (2*(1 + 2*(1 + x)))
    You can use Paint to draw the parse trees, or just type them in the text mode. For example, following the second approach a parse tree for the expression (a + b) * c should look like this:
            a   b 
             \ /
              +   c
               \ /
                *