Solution Manual for Introduction to Mechatronic Design Do Not Circulate
Chapter 3 Microcontroller Math and Number Manipulation
3.1) Convert the following binary patterns to hexadecimal:
1101
01010
10011
11001100
110011000001
3.2) Construct a comparison expression that will test if bits 0, 2 & 4 in a byte are all in the high state without
altering the state of the byte.
3.3) Construct an expression that will clear bits 1, 3 & 5 in a byte-sized variable called Bumpers while not
altering any of other bits.
3.4) Construct an expression that will set bit 1 in a byte-sized variable called PortA without affecting any of the
other bits in the variable.
3.5) Write out the 16 bit hexadecimal representation of the following signed decimal numbers (assume the
representation is 2’s complement):
10
17
27
-45
-128
127
10 = 0x000A
17 = 0x0011
3.6) Construct an expression that will test if either bit 0 or bit 3 in a byte-sized variable is in the high state
without altering the state of the byte.
3.7) Construct an expression that will test if either bit 1 or bit 3 in a byte-sized variable is in the low state
without altering the state of the byte.
3.8) What result would you expect from the following expressions if all values were contained in byte-sized
variables?
(240 × 2)/4
(240 × 2)/10
(240/10) × 2
(240/4) × 2
(240 × 2)/4 = 56
3.9) Construct an expression that will clear bit 1 in a byte-sized variable called PortA without altering any of
the other bits.
3.10) Construct an expression to toggle (change a zero to a 1 or a 1 to a zero) bit 3 in a byte-sized variable called
PortB that doesn’t alter the value of any of the other bits.
3.11) Construct an expression that quickly divides an integer variable by 32 without using the division operator.
3.12) Complete the blank cells in the following table:
Binary Hexadecimal
1 1100 0111
2 0110 1010
3 0001 1100
4 0101 1001
5 1011 0110
6 0xB4
7 0x1E
8 0x72
9 0x39
10 0xFF
Binary Hexadecimal
1 1100 0111 0xC7
3.13) What is the range of a 24 bit two’s compliment number?