Practice Problems Set 3
-
Fill in the blanks below:
- (1056)9 = ( )3
- (456)10 = ( )5
- (1023)4 = ( )2
= ( )16
- (156752)8 = ( )4
= ( )2
- In each of the cases below, write the HTML statement to specify the background colour of the
page to contain:
- 38 of green, 25 of blue and 100 of red.
- 57 of blue, 48 of green, 96 of red.
- Suppose a computer stores integers in 6 bits using the 2s
complement scheme. Write the binary representations for each of the
following numbers:
- 10
- -15
- -18
- -5
- 34
- -37
-
Using the laws of logic, show that the following logical equivalences
are true. (^ denotes and, v denotes or, ~ denotes
not and = denotes logical equivalence.)
- ((p ^ q) v ~p) = (~p v q).
- ~(p ^ ~q) = (~p ^ (q v p)).
- (~p ^ ~q ^ r) v (~p ^ q ^ r) v (p ^ ~q ^ r) v (p ^ q ^ r) = r.
- (~p ^ q ^ ~r) v ~(~p v (~q v r)) = (q ^ ~r).
- Using the laws of logic, prove that
- ((p --> q) ^ (p --> r)) = (p -> (q ^ r)).
- (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).
-
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.
- 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.
- 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.
- 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.
- 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.
- 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.)
- 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.)