You are on page 1of 4

DSE 163 Computer programing Concepts

Assignment 1

1. Construct truth tables for each the following expressions:

i. (A^B)vC

ii. X^(YvZ)

iii. (A^B) v (CvD)

I) (A^B)vC

A B C (A^B)vC

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 1

1 1 1 1
II) X^(YvZ)

X Y Z X^(YvZ)

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 0

1 0 0 1

1 0 1 1

1 1 0 1

1 1 1 1

III) (A^B)v(CvD)

A B C D (A^B) (CvD) (A^B)v(CvD)

0 0 0 0 0 0 0

0 0 0 1 0 1 1

0 0 1 0 0 1 1

0 0 1 1 0 1 1

0 1 0 0 0 0 0

0 1 0 1 0 1 1

0 1 1 0 0 1 1

0 1 1 1 0 1 1

1 0 0 0 0 0 0

1 0 0 1 0 1 1

1 0 1 0 0 1 1
1 0 1 1 0 1 1

1 1 0 0 1 0 1

1 1 0 1 1 1 1

1 1 1 0 1 1 1

1 1 1 1 1 1 1

2. Suppose we define a new integer datatype “MyInt” for which 3 Bytes are
allocated. How many integers can be represented by this data type?

If we allocate 3 bytes for the "MyInt" datatype, we need to calculate the total number of
distinct values that can be represented by these 3 bytes.

Each byte consists of 8 bits, and since we have 3 bytes, the total number of bits
available is 3 * 8 = 24 bits.

For each bit, there are two possible states: 0 or 1. Therefore, the total number of distinct
values that can be represented by 24 bits is 2^24.

Calculating 2^24 gives us 16,777,216.

Therefore, the "MyInt" datatype, with 3 allocated bytes, can represent a total of
16,777,216 different integers.

3. Suppose A = 4; B=5; and C = 10. Analyze the following expressions and


find the value of RESULT:
i. If (A < B) and (A<C) then RESULT = A else RESULT = 0;
ii. If (A>B) and (C<A) then RESULT = A else RESULT = 0;
iii. If (B%A>3) then RESULT = 7 else RESULT = 0;
iv. If (B+C)%A >=3 then RESULT = 100 else RESULT = 0;
Let's analyze each expression and find the value of RESULT based on the given values of
A = 4, B = 5, and C = 10:

i. If (A < B) and (A < C), then RESULT = A else RESULT = 0;


Here, (A < B) is true (4 < 5) and (A < C) is also true (4 < 10).
Since both conditions are true, RESULT = A = 4.

ii. If (A > B) and (C < A), then RESULT = A else RESULT = 0;


Here, (A > B) is false (4 > 5) and (C < A) is false (10 < 4).
Since both conditions are false, RESULT = 0.

iii. If (B%A > 3), then RESULT = 7 else RESULT = 0;


Here, (B % A) = (5 % 4) = 1, which is not greater than 3.
Therefore, the condition is false, and RESULT = 0.

iv. If ((B + C) % A) >= 3, then RESULT = 100 else RESULT = 0;


Here, ((B + C) % A) = ((5 + 10) % 4) = 15 % 4 = 3.
Since the condition ((B + C) % A) >= 3 is true, RESULT = 100.

Therefore, the values of RESULT for each expression are:


i. RESULT = 4
ii. RESULT = 0
iii. RESULT = 0
iv. RESULT = 100

You might also like