Practice Problems Set 3

  1. Fill in the blanks below:
    1. (1056)9 = (   )3
    2. (456)10 = (   )5
    3. (1023)4 = (   )2 = (   )16
    4. (156752)8 = (   )4 = (   )2

  2. In each of the cases below, write the HTML statement to specify the background colour of the page to contain:
    1. 38 of green, 25 of blue and 100 of red.
    2. 57 of blue, 48 of green, 96 of red.

  3. Suppose a computer stores integers in 6 bits using the 2s complement scheme. Write the binary representations for each of the following numbers:
    1. 10
    2. -15
    3. -18
    4. -5
    5. 34
    6. -37

  4. Using the laws of logic, show that the following logical equivalences are true. (^ denotes and, v denotes or, ~ denotes not and = denotes logical equivalence.)
    1. ((p ^ q) v ~p) = (~p v q).
    2. ~(p ^ ~q) = (~p ^ (q v p)).
    3. (~p ^ ~q ^ r) v (~p ^ q ^ r) v (p ^ ~q ^ r) v (p ^ q ^ r) = r.
    4. (~p ^ q ^ ~r) v ~(~p v (~q v r)) = (q ^ ~r).

  5. Using the laws of logic, prove that
    1. ((p --> q) ^ (p --> r)) = (p -> (q ^ r)).
    2. (p --> r) ^ (q --> r) = ((p v q) --> r).
    Show all your work, and write the law or identity used in each step of your derivation. Recall the following identity:
    (p --> q) = (~ p v q).
    

  6. Write HTML for a web page that has a form in it, where the form has three text boxes for the user to enter three numbers, a button, and another text box for displaying the result. Assume that the first three boxes are called num1, num2 and num3, and the last text box (where the results are to be displayed) is called result.
    1. Write a JavaScript function for the page so that when the user enters numbers in the first three boxes, and clicks on the button, the result box displays the largest of the three numbers.
    2. Write a JavaScript function for the page so that when the user enters numbers in the first three boxes, and clicks on the button, the result box displays the string "Valid" if one of the three numbers is the area of a rectangle whose sides have lengths equal to the other two numbers; the result box displays the string "Invalid" otherwise.
    3. Write a JavaScript function for the page so that when the user enters numbers in the first three boxes, and clicks on the button, the result box displays the string "Right Triangle" if the three numbers are the lengths of the three sides of a right-angled triangle; the result box should display the string "Not right triangle" otherwise.
    4. Write a JavaScript function for the page so that when the user enters numbers in the first three boxes, and clicks on the button, the result box displays the sum of all the numbers between, and including, the smallest of the three numbers and the largest of the three numbers.
    5. Write a JavaScript function for the page so that when the user enters numbers in the first three boxes, and clicks on the button, the result box displays the sum of the digits of the first number entered by the user. (Assume that the first number entered by the user is a non-negative number, and the second and third numbers entered by the user can be ignored.)
    6. Write a JavaScript function for the page so that when the user enters numbers in the first three boxes, and clicks on the button, the result box displays the binary representation of the first number entered by the user. (Assume that the first number entered by the user is a non-negative number, and the second and third numbers entered by the user can be ignored.)