Skip to main content
Contents
Dark Mode Prev Up Next
\(\newcommand{\N}{\mathbb N} \newcommand{\Z}{\mathbb Z} \newcommand{\Q}{\mathbb Q} \newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Exercises 14.10 Practice Problems
In questions 1-6, indicate the most efficient integer datatype to store the following variables.
1.
Temperature (in either degrees C or F) of a physical process.
2.
A number corresponding to the current day of the week.
3.
A number corresponding to the current day in the year.
4.
A number corresponding to the current month in the year.
5.
An address capable of addressing 64k of memory.
Answer . Solution .
\(\lceil\log_2{64\textrm{k}}\rceil = 16~\textrm{bits}\)
6.
The age of a person in years.
In questions 7-13, calculate the result of the following operations.
7.
unsigned char a = 0x05 + 0xF3;
8.
unsigned char a = 38 - 14;
9.
unsigned char a = 52 - 100;
10.
unsigned char a = 5 * 10;
11.
unsigned char a = (25 * 10) / 2;
12.
unsigned char a = (25 / 2) * 10;
13.
unsigned char a = 36 % 8;
In questions 14-16, calculate the value of
a after the following operations.
14.
15.
16.
17.
To selectively clear certain bits, which operator should be used?
18.
To selectively set certain bits, which operator should be used?
In questions 19-22, calculate the result of the following operations.
19.
20.
21.
(14 != 38) && (20 >= -10)
22.
In questions 23-27, calculate the final value of each variable after the compound operation has been executed.
23.
unsigned char a = 38;
a /= 9;
24.
25.
unsigned char j = 12;
j %= 7;
26.
unsigned char x = 0xAC;
x ^= 0xE9;
27.
unsigned char num = 22;
num &= 199;
In questions 28-30, determine the final value of the variable
x after the loop has been executed (assume in each question that the variable
x can be accessed immediately after the loop has finished executing).
28.
for (unsigned char x = 0; x > 6; x++) {
x += 10;
}
Answer . Solution .
The condition will never be met, the iterative code will never execute.
29.
unsigned int x = 1;
while (x <= 5) {
x *= 2;
}
30.
unsigned int x = 0;
do {
x++;
} while (x <= 20);