0% found this document useful (0 votes)
8 views6 pages

Azka - 05 Qs

Uploaded by

timothybonario
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Azka - 05 Qs

Uploaded by

timothybonario
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Azka Aulia Muhammad

ENGR1301 – A
2021 Spring Semester
05 Types - Tutorial Questions

1. What are the following in Decimal?


The 0 in the 1st digit is just the sign of Octal.

a) 07
7 x 8^0 = 7

b) 077
(7 x 8^1) + (7 x 8^0) = 56 + 7 = 63

c) 0777
(7 x 8^2) + (7 x 8^1) + (7 x 8^0) = 511

2. What are the following in Decimal?


The 0x in the 1st digit is just the sign of Hexadecimal.

a) 0x123
(1 x 16^2) + (2 x 16^1) +(3 x 16^0) = 291

b) 0x321
(3 x 16^2) + (2 x 16^1) +(1 x 16^0) = 801

c) 0XABC
(10 x 16^2) + (11 x 16^1) +(12 x 16^0) = 2748

d) 0XCBA
(12 x 16^2) + (11 x 16^1) +(10 x 16^0) = 3258

3. What are the following in Hexadecimal?


Convert it from Octal to Decimal first.
Then we divide it by 16 and take the remainders as the
Hexadecimal digits.

a) 07
7 x 8^0 = 7
7 : 16 = 0 | R = 7
= 7

b) 077
(7 x 8^1) + (7 x 8^0) = 56 + 7 = 63
63 : 16 = 3 | R = 15 (F)
3 : 16 = 0 | R = 3

= 3F

c) 0777
(7 x 8^2) + (7 x 8^1) + (7 x 8^0) = 511
511 : 16 = 31 | R = 15 (F)
31 : 16 = 1 | R = 15 (F)
1 : 15 = 0 | R = 1

= 1FF

4. What are the following in Octal?


Convert it from Hexadecimal to Decimal first.
Then we divide it by 8 and take the remainders as the Octal
digits.
a) 0x123
(1 x 16^2) + (2 x 16^1) +(3 x 16^0) = 291
291 : 8 = 36 | R = 3
36 : 8 = 4 | R = 4
4 : 8 = 0 | R = 4

= 443

b) 0x321
(3 x 16^2) + (2 x 16^1) +(1 x 16^0) = 801
801 : 8 = 100 | R = 1
100 : 8 = 12 | R = 4
12 : 8 = 1 | R = 4
1 : 8 = 0 | R = 1

= 1441

c) 0XABC
(10 x 16^2) + (11 x 16^1) +(12 x 16^0) = 2748
2748 : 8 = 343 | R = 4
343 : 8 = 42 | R = 7
42 : 8 = 5 | R = 2
5 : 8 = 0 | R = 5
= 5274

d) 0XCBA
(12 x 16^2) + (11 x 16^1) +(10 x 16^0) = 3258
3258 : 8 = 407 R 2
407 : 8 = 50 R 7
50 : 8 = 6 R 2
6 : 8 = 0 R 6
= 6272

5. Which of the following are not legal constants in C?

a) 010E2
It is a legal float
The result is 1000.000000.

b) 32.1E+5
It is a legal float.
The result is 321000.

c) 0790
It is an illegal constant.
If it is started by 0, it is an octal. However, the digits of
octal only ranges from 0 to 7, “9” will not be accepted.

d) 100_000
It is an illegal constant.
Cannot exist in any constant, not even in decimal.
Underscore is not allowed in a constant.

e) 3.978e-2
It is a legal float
The result will be 0.039780

The answer is d because it uses underscore which is not


allowed to place in a constant. Therefore, the program will not
be compiled.
6. Assuming an ASCII character set, which one of the following
is not a legal way to write the number 65?

a) ‘A’
b) 0b1000001
c) 0101
d) 0x41

The answer is b because it is in binary (not the standard


constant of C). Therefore, it is not legal. The other options
give the exact value of 65.

7. For each of the following types of data, specify which one


of char, short, int or long is the smallest one guaranteed
to be able to store the data.

(Assume that is in 16-bit machine).

a) Days in a month = 28, 29, 30, or 31


The answer is char type.
Because char ranges from 0 to 255.
Therefore, it is safe to accommodate.

b) Days in a year = 365 or 366


The answer is short type.
Because short ranges from -32768 to 32767.
Therefore, it is safe to accommodate.

c) Minutes in a day = 1440


The answer is short type.
Because short ranges from -32768 to 32767.
Therefore, it is safe to accommodate.

d) Seconds in a day = 86400


The answer is long type.
Because long ranges from -2,147,483,648 to 2,147,483,647.
Therefore, it is safe to accommodate.
8. Suppose that i and j are of type int. What is the type of

i / j + ‘a’ ?

The answer is int because int a has wider range than chars
(‘a’). Int can accommodate the operands.

9. Suppose that i is an int, f is a float and d is a double.


What type is

i * f / d ?

The answer is double because double has a wider range than


float. Double can accommodate all other types in this
expression.

10. Assuming

char c = ‘1’;
short s = 2;
int i = -3;
long m = 5;
float f = 6.5f
double d = 7.5;

give the value and type of

a) c * i
49 * -3 = -157
The type is int because int has a wider range than char.
Int is safer to accommodate both the operands.

b) s + m
2 + 5 = 7
The type is long because long has a wider range than short.
long is safer to accommodate both the operands.

c) f / c
6.5 / 49 = 0.132653
The type is float because float has a wider range than char.
Float is safer to accommodate both the operands.
d) d / s
7.5 / 2 = 3.75
The type is double because double has a wider range than short.
Double is safer to accommodate both the operands.

e) f – d
6.5f – 7.5 = -1
The type is double because double has a wider range than float.
Double is safer to accommodate both the operands.

f) (int) f
= 7
Because it will be truncated after f is casted to int (the
decimal will not be brought).

11. Use typedef to create types to represent 8-bit, 16-bit and


32-bit integers.

typedef int8_t int8;


typedef int16_t int16;
typedef int32_t int32;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy